fix(eslint-plugin-react-compiler): add TypeScript type declarations#574
fix(eslint-plugin-react-compiler): add TypeScript type declarations#574everettbu wants to merge 2 commits into
Conversation
Add a hand-written index.d.ts to provide TypeScript types for eslint-plugin-react-compiler. This fixes the implicit 'any' type error when importing the plugin with checkJs enabled in tsconfig.json. The declaration file exports the three public symbols: configs, rules, and meta. Closes #31334
Greptile SummaryAdds hand-written TypeScript type declarations (
Confidence Score: 4/5
Important Files Changed
Last reviewed commit: 36045c1 |
| recommended: { | ||
| plugins: { | ||
| 'react-compiler': { | ||
| rules: Record<string, {rule: Rule.RuleModule; severity: string}>; |
There was a problem hiding this comment.
Severity type could be more precise
The runtime type for severity is ErrorSeverity (from babel-plugin-react-compiler), which is an enum with values 'Error' | 'Warning' | 'Hint' | 'Off'. Using string here is technically correct but loses type specificity for consumers. Consider using a string literal union instead:
| rules: Record<string, {rule: Rule.RuleModule; severity: string}>; | |
| rules: Record<string, {rule: Rule.RuleModule; severity: 'Error' | 'Warning' | 'Hint' | 'Off'}>; |
This would give consumers better autocomplete and type safety without needing to import across package boundaries.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: compiler/packages/eslint-plugin-react-compiler/index.d.ts
Line: 18
Comment:
**Severity type could be more precise**
The runtime type for `severity` is `ErrorSeverity` (from `babel-plugin-react-compiler`), which is an enum with values `'Error' | 'Warning' | 'Hint' | 'Off'`. Using `string` here is technically correct but loses type specificity for consumers. Consider using a string literal union instead:
```suggestion
rules: Record<string, {rule: Rule.RuleModule; severity: 'Error' | 'Warning' | 'Hint' | 'Off'}>;
```
This would give consumers better autocomplete and type safety without needing to import across package boundaries.
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.
Mirror of facebook/react#35856
Original author: sleitor
Summary
Add a hand-written
index.d.tsto provide TypeScript types foreslint-plugin-react-compiler. This fixes the implicitanytype error when importing the plugin withcheckJsenabled in tsconfig.json.The declaration file exports the three public symbols:
configs,rules, andmeta.Fixes #31334
Changes
index.d.tswith type declarations for the plugin's public API"types": "index.d.ts"topackage.jsonindex.d.tstofilesarray so it's included in npm package