Skip to content
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

Open
2 tasks done
CHC383 opened this issue Jan 14, 2025 · 2 comments · May be fixed by #3879
Open
2 tasks done

[enhancement]: flat configs are possibly undefined #3878

CHC383 opened this issue Jan 14, 2025 · 2 comments · May be fixed by #3879

Comments

@CHC383
Copy link

CHC383 commented Jan 14, 2025

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

This is a follow up of #3874, since flat is Record<string, ReactFlatConfig>, flat.xxx or flat["xxx"] could be undefined. The fix might be explicitly list recommended, all and jsx-runtime as the key of the Record instead of using string.

Image
import tseslint from 'typescript-eslint'
import reactPlugin from 'eslint-plugin-react'

export default tseslint.config(
  reactPlugin.configs.flat.recommended
)
Argument of type 'ReactFlatConfig | undefined' is not assignable to parameter of type 'InfiniteDepthConfigWithExtends'.

Expected Behavior

No type error

eslint-plugin-react version

v7.37.4

eslint version

9.17.0

node version

v22.13.0

@CHC383 CHC383 added the bug label Jan 14, 2025
CHC383 added a commit to CHC383/eslint-plugin-react that referenced this issue Jan 14, 2025
@CHC383 CHC383 linked a pull request Jan 14, 2025 that will close this issue
@ljharb
Copy link
Member

ljharb commented Jan 14, 2025

To be clear, this is not a bug - the types are correct - but you're right they could be more helpful.

@ljharb ljharb changed the title [Bug]: flat configs are possibly undefined [enhancement]: flat configs are possibly undefined Jan 14, 2025
CHC383 added a commit to CHC383/eslint-plugin-react that referenced this issue Jan 14, 2025
CHC383 added a commit to CHC383/eslint-plugin-react that referenced this issue Jan 14, 2025
CHC383 added a commit to CHC383/eslint-plugin-react that referenced this issue Jan 14, 2025
CHC383 added a commit to CHC383/eslint-plugin-react that referenced this issue Jan 14, 2025
@CHC383
Copy link
Author

CHC383 commented Jan 14, 2025

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants