Description
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.
Relevant Package
- parser
- eslint-plugin
Playground Link
No response
Repro Code
ESLint has a new “flat” config system:
- https://eslint.org/docs/latest/use/configure/configuration-files-new#using-plugins-in-your-configuration
- https://eslint.org/docs/latest/use/configure/configuration-files-new#configuring-a-custom-parser-and-its-options
Unfortunately, when attempting to import and use the TypeScript ESLint plugin and parser within the ESLint config of type import("eslint").Linter.FlatConfig
they result in TypeScript errors.
In eslint.config.js
:
// @ts-check
import eslintPluginTypescript from "@typescript-eslint/eslint-plugin";
import eslintParserTypescript from "@typescript-eslint/parser";
/**
* ESLint config.
* @satisfies {Array<import("eslint").Linter.FlatConfig>}
*/
const eslintConfig = [
{
languageOptions: {
parser: eslintParserTypescript,
},
plugins: {
"@typescript-eslint": eslintPluginTypescript,
},
},
];
export default eslintConfig;
ESLint Config
No response
tsconfig
No response
Expected Result
The TypeScript ESLint plugin and parser should be usable within ESLint “flat” config of type import("eslint").Linter.FlatConfig
without causing TypeScript errors.
Actual Result
The languageOptions.parser
has this TypeScript error:
Type 'typeof import("[redacted]/node_modules/@typescript-eslint/parser/dist/index")' is not assignable to type 'ParserModule | undefined'.
Type 'typeof import("[redacted]/node_modules/@typescript-eslint/parser/dist/index")' is not assignable to type 'ObjectMetaProperties & { parseForESLint(text: string, options?: any): ESLintParseResult; }'.
Type 'typeof import("[redacted]/node_modules/@typescript-eslint/parser/dist/index")' is not assignable to type '{ parseForESLint(text: string, options?: any): ESLintParseResult; }'.
The types of 'parseForESLint(...).ast.comments' are incompatible between these types.
Type 'Comment[] | undefined' is not assignable to type 'Comment[]'.
Type 'undefined' is not assignable to type 'Comment[]'.
The plugins["@typescript-eslint"]
has this TypeScript error:
Type '{ configs: Record<string, Config>; rules: TypeScriptESLintRules; }' is not assignable to type 'Plugin'.
Types of property 'rules' are incompatible.
Type 'TypeScriptESLintRules' is not assignable to type 'Record<string, RuleModule | ((context: RuleContext) => RuleListener)>'.
'string' index signatures are incompatible.
Type 'RuleModule<string, unknown[], RuleListener>' is not assignable to type 'RuleModule | ((context: RuleContext) => RuleListener)'.
Type 'RuleModule<string, unknown[], RuleListener>' is not assignable to type 'RuleModule'.
Types of property 'create' are incompatible.
Type '(context: Readonly<RuleContext<string, unknown[]>>) => RuleListener' is not assignable to type '(context: RuleContext) => RuleListener'.
Types of parameters 'context' and 'context' are incompatible.
Type 'RuleContext' is not assignable to type 'Readonly<RuleContext<string, unknown[]>>'.
The types of 'parserOptions.ecmaVersion' are incompatible between these types.
Type '3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 2024 | "latest" | undefined' is not assignable to type '"latest" | EcmaVersion | undefined'.
Type '14' is not assignable to type '"latest" | EcmaVersion | undefined'.

Additional Info
The TypeScript ESLint project should be using the same ESLint types from @types/eslint
like the rest of the ecosystem is using, instead of internally maintaining separate types. Where there are problems with the @types/eslint
types they should be fixed in contributions so the entire ecosystem benefits.
This attitude is upsetting:
typescript-eslint/packages/utils/typings/eslint.d.ts
Lines 1 to 6 in 951a3bb
I have run into frustrations before because Microsoft have not been participating in contributing to the main ESLint types the community is using, and as a consequence they are of poor quality.
Versions
package | version |
---|---|
@typescript-eslint/eslint-plugin |
6.4.0 |
@typescript-eslint/parser |
6.4.0 |
TypeScript |
5.1.6 |
ESLint |
8.47.0 |
node |
20.5.0 |