-
-
Notifications
You must be signed in to change notification settings - Fork 12
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: @eslint/compat types incompatible with both typescript-eslint and @types/eslint #25
Comments
Also, the argument type of the first argument of import { fixupPluginRules } from '@eslint/compat';
// typescript-eslint
const typescriptEslintPlugin =
/** @type {import('@typescript-eslint/utils/ts-eslint').FlatConfig.Plugin} */ ({});
fixupPluginRules(typescriptEslintPlugin); // 💥 Argument of type 'Plugin' is not assignable to parameter of type 'FixupPluginDefinition'.
// ... (see full error below)
// @types/eslint
const eslintPlugin = /** @type {import('eslint').ESLint.Plugin} */ ({});
fixupPluginRules(eslintPlugin); // 💥 Argument of type 'Plugin' is not assignable to parameter of type 'FixupPluginDefinition'.
// ... (see full error below) I also added this as a file Errors:
|
Thanks for the report. Unfortunately, the team doesn't have a lot of experience with TypeScript (this is one of the first packages we've published with type definitions), so I'm not surprised that there are conflicts. I (naively) thought that by defining interfaces, then anything matching that interface would be accepted. Also unfortunately, it seems that others have gone ahead and created type definitions for ESLint that we weren't involved in (such as As it seems like you have a great deal of insight into this problem, would you be willing to put together a proposal for how to address this? |
Thanks for the candid feedback and openness to make a change here! For additional feedback regarding "the future of TS types in official ESLint projects" I would like to defer to community members who have worked on the
My first gut feel - given the years of existing, detailed work in A)
In future, if the ESLint project has interest, then For example, below would be a first quick sketch (generated code, not tested to be accurate or compatible types) of using the DefinitelyTyped packages
/**
* @filedescription Types for backcompat package.
*/
import type { Rule, Linter, Scope, SourceCode } from 'eslint';
import { Node as ESTreeNode } from 'estree';
/*
* NOTE: These are minimal type definitions to help avoid errors in the
* backcompat package. They are not intended to be complete and should be
* replaced when the actual types are available.
*/
export type FixupLegacyRuleDefinition = (
context: Rule.RuleContext,
) => Rule.RuleListener;
export interface FixupRuleDefinition {
meta?: Rule.RuleMetaData;
create(context: Rule.RuleContext): Rule.RuleListener;
}
export interface FixupPluginDefinition {
meta?: object;
rules?: Record<string, FixupRuleDefinition>;
configs?: Record<string, Linter.Config>;
processors?: Record<string, Linter.Processor>;
}
export interface FixupConfig {
files?: string[];
ignores?: string[];
name?: string;
languageOptions?: {
ecmaVersion?: number | 'latest';
sourceType?: 'script' | 'module';
globals?: Record<string, boolean | 'readonly' | 'writable' | 'writeable'>;
parser?: string;
parserOptions?: Linter.ParserOptions;
};
linterOptions?: {
noInlineConfig?: boolean;
reportUnusedDisableDirectives?: boolean | Linter.RuleLevel;
};
processor?: string | Linter.Processor;
plugins?: Record<string, FixupPluginDefinition>;
rules?: Record<string, Linter.RuleEntry>;
}
export type FixupConfigArray = FixupConfig[]; @nzakas What are your thoughts on this idea of consuming the DefinitelyTyped community packages like this? |
What would be the benefit of that vs. just using the types from |
By "using the types", do you mean copying the types instead of importing them? In that case, the benefit of importing + adding a dependency vs. copying the types would be that any incompatible updates to types on either side (either There would be ways around this, eg:
But these options would lead to more work, maintenance and indirection in the code. |
Or maybe I misunderstood: maybe by "using the types" you mean importing more of the types that are already created, effectively removing most or all new types in (any new types which are needed could also be contributed back to That seems to me like an even better approach, if it is agreeable! (as it adds back to the community efforts that are going on in those packages) |
Yes, exactly. As I mentioned, we on the team aren't super familiar with TypeScript and I was relying on my experience of using interfaces in other languages when putting this together. If we can use the types of What I don't want to do is end up maintaining |
Seems pretty good to me - rely on the things that are already available.
Understood, taking over a large project created and maintained by others is not easy. Two notes here:
That's my take on this, maybe a DefinitelyTyped or TS or |
Just to be clear, I have not personally worked on Just for the immediate feedback, I would definitely be trying to get the types here in better shape. Using I would probably consider depending on As for ESLint itself publishing types, I think that comes down to how breaky you want that to be. Realistically, the best situation is to adopt the types from |
Just to be clear, I wasn't suggesting we'd export types from the For the rewritten core, though, we'll definitely be exporting our own types. |
Originally reported in typescript-eslint/typescript-eslint#9115
Which packages are affected?
@eslint/compat
@eslint/config-array
@eslint/object-schema
Environment
Node version: v20.13.1
npm version: 10.5.2
ESLint version: 9.3.0
Operating System: macOS Sonoma 14.5 (23F79)
What did you do?
I used
fixupPluginRules()
from@eslint/compat
along with thetseslint.config()
config definition function fromtypescript-eslint
and received a type mismatch:See full error below under "What actually happened?".
I also tried the
Linter.FlatConfig[]
type fromeslint
itself:See full error below under "What actually happened?".
My
package.json
:What did you expect to happen?
The types from
@eslint/compat
should be compatible with both:tseslint.config()
config definition function fromtypescript-eslint
Linter.FlatConfig[]
type from@types/eslint
What actually happened?
The types were reported as incompatible with both:
1.
typescript-eslint
tseslint.config()
config definition function fromtypescript-eslint
(the types of both
typescript-eslint@7.9.0
andtypescript-eslint@8.0.0-alpha.14
result in the same problem, I chose v8 alpha for its support of ESLint 9)2.
@types/eslint
Linter.FlatConfig[]
type from@types/eslint
This is similar to the outcome with
fixupConfigRules
reported in #24Cause
Apparently the types of
@eslint/compat
are using loose, problematic types likeObject
, as @bradzacher mentions here:fixupPluginRules()
from@eslint/compat
typescript-eslint/typescript-eslint#9115 (comment)These appear to have been added as part of #5 here:
3957064
(#5)Link to Minimal Reproducible Example
tsc
automatically to show errors in Terminal) https://codesandbox.io/p/devbox/github/karlhorky/repro-eslint-compat-types-incompatibleParticipation
Additional comments
No response
The text was updated successfully, but these errors were encountered: