-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[enhancement]: flat configs are possibly undefined #3878
Comments
To be clear, this is not a bug - the types are correct - but you're right they could be more helpful. |
Just to share a workaround for Typescript users until we figure out how to type the configs properly // @ts-expect-error https://github.com/jsx-eslint/eslint-plugin-react/issues/3878
reactPlugin.configs.flat.recommended, |
As a workaround, I added a // eslint-plugin-react.d.ts
declare module 'eslint-plugin-react' {
export const configs: typeof configs & {
flat: Record<'all' | 'recommended' | 'jsx-runtime', ReactFlatConfig>; // the original type is Record<string, ReactFlatConfig>
};
} This could be a fix for this lib but I see there is already an open PR. I can propose this fix in another PR if it makes sense |
Please don’t open an additional PR; if you have a fix that could work, please post a link to the branch on the existing PR. |
The fix is just there. The branch is more a refactor with a breaking change, this is why I offered to create a simpler PR with the mentioned typing fix. |
Since our types are built, that isn’t a possible fix we can apply, unfortunately. |
I don't understand, if your types are generated from the JSDocs, then the fix seems pretty simple; Change Line 100 in e6b5b41
Or am I missing something? |
@3dos There were two attempts to fix this issue, #3879 and #3882, #3879 was taking the same approach as yours and it didn't work due to #3879 (comment), you could try it yourself by applying your changes locally and test it through #3879 (comment) |
Is there an existing issue for this?
Description Overview
This is a follow up of #3874, since
flat
isRecord<string, ReactFlatConfig>
,flat.xxx
orflat["xxx"]
could be undefined. The fix might be explicitly listrecommended
,all
andjsx-runtime
as the key of the Record instead of usingstring
.Expected Behavior
No type error
eslint-plugin-react version
v7.37.4
eslint version
9.17.0
node version
v22.13.0
The text was updated successfully, but these errors were encountered: