Closed
Description
Is there an existing issue for this?
- I have searched the existing issues and my issue is uniqueMy issue appears in the command-line and not only in the text editor
Description Overview
The types as exported in #3797 and #3836 are broken and throw TS errors while used. The package only exports named namespace of configs
, which means you can't do any of the following:
import react from 'eslint-plugin-react';
import { config } from 'typescript-eslint';
export default config({
plugin: { react },
rules: {
...react.configs.recommended.rules,
...someMoreRules
}
});
Expected Behavior
No TS error.
eslint-plugin-react version
v7.37.1
eslint version
v8.57.0
node version
v20.9.0
typescript version
All, tested on v5.5.2, v.5.6.2
Activity
JstnMcBrd commentedon Oct 1, 2024
This appears to be because only the
flat
configs are included in the types. You can doreactPlugin.configs.flat.recommended
, but you can't access the legacy configs withreactPlugin.configs.recommended
.burtek commentedon Oct 1, 2024
Oh, that's true (though still not in line with what's actually exported). But I still can't do
plugin: { react }
burtek commentedon Oct 1, 2024
And the
flat
config is not typescript-eslint compatible either...JstnMcBrd commentedon Oct 1, 2024
Yes, I was able to add that - even the flat config types are broken. They appear to be incompatible with ESLint's types.
On first glance, I wonder if this is because the type appears to have some recursion. It's possible to do
reactPlugin.configs.flat.recommended.plugins.react.configs.recommended
.The flat configs contain the legacy configs. Is that intentional? That might be the problem.
ljharb commentedon Oct 2, 2024
@JstnMcBrd yes, that's intentional and unavoidable with the current architecture of the plugin.
burtek commentedon Oct 2, 2024
I can probably look into fixing types today or tomorrow, no promises though
EDIT: so far wasn't able to
damisparks commentedon Oct 2, 2024
I am having the same issue.
karlhorky commentedon Oct 6, 2024
Workaround
Use JSDoc-style type assertion to fix the types:
eslint.config.js
Or, if you use
eslint.config.ts
(ESLint 9.9.0+ experimental feature), use a TypeScript type assertion:eslint.config.ts
eslint-plugin-react
fromimport-types.d.ts
burtek/eslint-config#20014 remaining items