-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: Type for values of SharedConfigs should allow an array #10213
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
Comments
Really we should remove that property entirely. |
While there might not be a strict requirement, I think plugins should expose a common interface, otherwise it would be impractical to use them. The ESLint docs say:
So they do expect you to structure your plugin in a certain way. I wanted to use the I found another thing that made it impractical to use this type though. All the properties are optional, so even though I specify them, users of the plugin will see them as optional and have to do a non-null assertion. But I can use e.g. |
According to the docs for ESLint an array should be allowed here, and the type used by ESLint in their `ESLint.Plugin` interface is: Record<string, Linter.LegacyConfig | Linter.Config | Linter.Config[]> | undefined So we should also allow an array. The helper function `tseslint.config` returns an array so without this you're not allowed to use a config returned by this function as a value in this record. Fixes typescript-eslint#10213
According to the docs for ESLint an array should be allowed here, and the type used by ESLint in their `ESLint.Plugin` interface is: Record<string, Linter.LegacyConfig | Linter.Config | Linter.Config[]> | undefined So we should also allow an array. The helper function `tseslint.config` returns an array so without this you're not allowed to use a config returned by this function as a value in this record. Fixes typescript-eslint#10213
They don't -- meta, rules, processors are the important ones. ESLint generally has recommended people export There's no real consistency in the ecosystem right now, to be honest. |
It's not required, and there may not be consistency in the ecosystem right now, but ESLint do suggest exporting configs in this specific way. The docs say:
And doesn't mention another way of exposing configs. Wouldn't it then make sense to have a type that matches this? Using the type/property is optional after all. I'm just going from what I'm reading on this docs page, so you have more context about this than me, but I would think what that page describes is what the ESLint authors intends. |
I realized now that using this type ( I could still us it with a |
This is exactly the problem. There is a lot of variance that is accepted within the ecosystem right now - so at best I'd want to specify like |
Maybe it would be useful to have a helper function (like
|
Found the same issue with typings and to be honest it's very confusing. I want to highlight that ESLint currently officially says that shared config in a plugin can be either object or array.
Now, let's imaging that we have 2 shared configs:
and I (as a developer of a plugin) want to extend In a
Thus, if you have shared configs in a So, it's practically impossible right now to have fully typed plugin object without any workaround. Related piece of the code: typescript-eslint/packages/utils/src/ts-eslint/Config.ts Lines 152 to 154 in 4af866a
I even tried to find how |
this is exactly just the |
Oh, yeah that's true. Then I guess there's no point in it. |
@maks-rafalko Is there something in your response that is not addressed by the resolution for which this issue is accepting PRs (#10213 (comment))? |
@kirkwaiblinger sorry, probably I didn't get neither your comment nor the comment you are referencing (for me, it doesn't sound like resolution). Anyway, I thought suggested typescript-eslint/packages/utils/src/ts-eslint/Config.ts Lines 152 to 154 in 4af866a
I'm not familiar with the codebase so don't take my words seriously, but I thought that the simplest solution could be like this: interface SharedConfigs {
- [key: string]: Config;
+ [key: string]: Config | ConfigArray;
} does it makes sense? If not, then please elaborate on
|
Including legacy config would mean mixing
This is what I have already proposed in PR #10217. |
Right, exactly, all I'm getting at is that my understanding is that all parties agree that #10217 (which implements the intended meaning of #10213 (comment)) is the appropriate resolution then π So I was double checking that there wasn't an additional, unaccounted-for concern raised in #10213 (comment) that we needed to hash out still. π |
Before You File a Bug Report Please Confirm You Have Done The Following...
Relevant Package
utils
Playground Link
No response
Repro Code
ESLint Config
No response
tsconfig
No response
Expected Result
The code should type check without errors. The code is a stripped down version of the example given on https://eslint.org/docs/latest/extend/plugins#configs-in-plugins except that I've replaced
Object.assign
with a direct assignment becauseObject.assign
doesn't type check that it can be assigned.You can see in that example that they set the recommended config to an array, but that's not allowed by the
SharedConfigs
type used byTSESLint.FlatConfig.Plugin["configs"]
. If you replaceTSESLint.FlatConfig.Plugin
withESLint.Plugin
you can also see that it type checks without errors.Actual Result
Type checking complains that an array can't be assigned to the type
Config
(the type for the values ofSharedConfigs
).Additional Info
No response
Versions
@typescript-eslint/utils
8.11.0
TypeScript
5.6.3
ESLint
9.13.0
node
20.17.0
The text was updated successfully, but these errors were encountered: