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

Bug: Type inference error when using tseslint.config() with eslint-plugin-react #8522

Closed
4 tasks done
printfn opened this issue Feb 21, 2024 · 3 comments
Closed
4 tasks done
Labels
bug Something isn't working external This issue is with another package, not typescript-eslint itself

Comments

@printfn
Copy link

printfn commented Feb 21, 2024

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Issue Description

Using eslint-plugin-react inside of the tseslint.config() function in eslint.config.js causes the following type error in VS Code:

Argument of type '{ plugins: { react: { deprecatedRules: { [x: string]: any; [x: number]: any; [x: symbol]: any; }; rules: any; }; }; rules: { [x: string]: number; [x: number]: number; [x: symbol]: number; }; readonly languageOptions: any; } & { ...; }' is not assignable to parameter of type 'ConfigWithExtends'.
  Types of property 'plugins' are incompatible.
    Type '{ react: { deprecatedRules: { [x: string]: any; [x: number]: any; [x: symbol]: any; }; rules: any; }; }' is not assignable to type 'Plugins'.
      Property 'react' is incompatible with index signature.
        Object literal may only specify known properties, and 'deprecatedRules' does not exist in type 'Omit<Plugin, "configs">'.

eslint.config.js:

// @ts-check

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintReact from 'eslint-plugin-react/configs/recommended.js';
import jsxRuntime from 'eslint-plugin-react/configs/jsx-runtime.js';

export default tseslint.config(
	eslint.configs.recommended,
	...tseslint.configs.recommended,
	eslintReact, // type error is on this line
	jsxRuntime,
	{
		settings: {
			react: {
				version: 'detect',
			},
		},
		languageOptions: {
			parserOptions: {
				project: ['./tsconfig.json', './tsconfig.node.json'],
			},
		},
	},
);

I'm not sure if this is a bug in eslint-plugin-react or typescript-eslint, but given that eslint still works correctly and this is purely a type error I opened an issue here.

Reproduction Repository Link

https://github.com/printfn/tseslint-react-repro

Repro Steps

  1. Clone the repo
  2. npm install
  3. Open the repository in VS Code and open the eslint.config.js file
  4. Notice that the line eslintReact has a type error

Versions

package version
@typescript-eslint/eslint-plugin 7.0.2
@typescript-eslint/parser 7.0.2
@typescript-eslint/scope-manager 7.0.2
@typescript-eslint/typescript-estree 7.0.2
@typescript-eslint/type-utils 7.0.2
@typescript-eslint/utils 7.0.2
TypeScript 5.3.3
ESLint 8.56.0
node 21.6.2
@printfn printfn added bug Something isn't working triage Waiting for maintainers to take a look labels Feb 21, 2024
@bradzacher
Copy link
Member

For some reason they export a deprecatedRules property on their plugin. It's been there for quite some time (>8y). Dunno why but that's neither here nor there. 🤷‍♂️

There's a weird thing happening. I can reproduce the error in your repro but I can't reproduce it in the playground.

I'm not sure why TS is erroring on this.
The assignment is completely valid based on structural typing.

Filed an upstream issue:
microsoft/TypeScript#57460

@bradzacher bradzacher added external This issue is with another package, not typescript-eslint itself blocked by external API Blocked by a tool we depend on exposing an API, such as TypeScript's Type Relationship API labels Feb 21, 2024
@bradzacher
Copy link
Member

Filed jsx-eslint/eslint-plugin-react#3694 which should fix a flat config bug and also fix this type issue.

@bradzacher bradzacher removed the triage Waiting for maintainers to take a look label Feb 21, 2024
@bradzacher
Copy link
Member

Closing as there's nothing we can do about this:

  1. it's a confirmed bug in TS's inference for untyped modules and not an issue with our types
  2. it can be improved and fixed by some minimal annotations to the react plugin

@bradzacher bradzacher removed the blocked by external API Blocked by a tool we depend on exposing an API, such as TypeScript's Type Relationship API label Feb 21, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working external This issue is with another package, not typescript-eslint itself
Projects
None yet
Development

No branches or pull requests

2 participants