fix(eslint-config-fluid): resolve TypeScript errors in flat config types#26424
fix(eslint-config-fluid): resolve TypeScript errors in flat config types#26424tylerbutler wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…d print-configs Fix 13 TS errors across base.mts and print-configs.ts: base.mts: Add type assertions for third-party ESLint plugin types (typescript-eslint, import-x, rushstack, prettier) whose .d.ts declarations don't yet match ESLint 9's updated type interfaces. print-configs.ts: Accept readonly config arrays from as-const exports, fix outputPath possibly-undefined, remove invalid sortJson indentSize option, and remove unused FlatConfigArray type alias.
There was a problem hiding this comment.
Pull request overview
This PR updates eslint-config-fluid’s ESLint 9 flat-config tooling to resolve TypeScript type incompatibilities introduced by third-party plugin .d.ts definitions and to improve readonly compatibility in the config printing script.
Changes:
- Adjust
print-configs.tsto accept readonly flat config arrays and fix a possibly-undefinedoutputPath. - Add targeted type assertions in
base.mtsfor third-party plugin/config exports whose declared types don’t match ESLint 9’s interfaces. - Remove the invalid
indentSizeoption from the in-memorysort-jsoncall.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| common/build/eslint-config-fluid/scripts/print-configs.ts | Accepts readonly config arrays and fixes TS errors around overrideConfig and outputPath. |
| common/build/eslint-config-fluid/library/configs/base.mts | Adds type assertions for plugin/config exports to align with ESLint 9 flat-config typings. |
alexvy86
left a comment
There was a problem hiding this comment.
One small thing below. I think it would be nice to have references to existing open issues in the new comments but I could not find any. Oh well.
| }, | ||
| // Prettier disables conflicting rules - must come after custom rules | ||
| prettierConfig, | ||
| prettierConfig as Linter.Config, |
There was a problem hiding this comment.
Add a comment like the ones above?
There was a problem hiding this comment.
Should be able to just remove this cast similar to removing tseslint.configs.* casts.
| // Type assertions needed: typescript-eslint's PluginFlatConfig.languageOptions lacks the | ||
| // string index signature that ESLint core's LanguageOptions requires. | ||
| ...(tseslint.configs.recommendedTypeChecked as Linter.Config[]), | ||
| ...(tseslint.configs.stylisticTypeChecked as Linter.Config[]), |
There was a problem hiding this comment.
Are you certain erasing the specific types from these are correct? I have a strong feeling that issue can be resolved without these casts. We should limit as as much as possible.
There was a problem hiding this comment.
Do you have something specific in mind?
There was a problem hiding this comment.
I looked at the error and I am confused. When I try to inspect things VS Code says that the type of these are
{
name?: string;
rules?: object;
}[]The visible error shown is a complaint about LanguageOptions. That doesn't add up.
If you remove the other entries following those, then there isn't a complaint. I narrowed it down to lines 65, 66, and 72 as contributing to the problem.
If you comment those out, then there is no error.
You can see that importXPlugin is more of the issue. Temporarily adding:
const X = tseslint.configs.recommendedTypeChecked satisfies Linter.Config[];
const Y = importXPlugin.flatConfigs.recommended satisfies Linter.Config;will show that importXPlugin does not satisfy Linter.Config, which you already know as those lines have been changed.
I think TypeScript error is bad (bug) and these casts can be removed. You can use satisfies in place of as on these lines. Then the comment for casting moves down to importXPlugin that is a real problem.
There was a problem hiding this comment.
Thanks for the reminder of satisfies. I keep forgetting about it.
jason-ha
left a comment
There was a problem hiding this comment.
Putting a light block here - see prior questions
| type FlatConfigArray = Linter.Config[]; | ||
|
|
||
| interface ConfigToPrint { | ||
| name: string; | ||
| config: FlatConfigArray; | ||
| config: readonly Linter.Config[]; |
There was a problem hiding this comment.
Alternatively import FlatConfigArray from base.mts definition? That definition also makes Linter.Config readonly (= readonly Readonly<Linter.Config>[])
Conversation acknowledged - hard block no longer required
|
While here print-configs.ts's const configsToPrint = [
...
] as const satisfies readonly ConfigToPrint[];since it is a constant. |
Summary
base.mtsfor third-party ESLint plugin types (typescript-eslint, import-x, rushstack, eslint-config-prettier) whose.d.tsdeclarations don't match ESLint 9's updated type interfacesprint-configs.tsto accept readonly config arrays fromas constexports, removing the need for shallow copies at each call siteoutputPathpossibly-undefined errorindentSizeoption fromsortJsoncall —indentSizeonly applies to sort-json's file-writing overload, not the in-memory sorting overload used here. Formatting is already handled byJSON.stringify(sortedConfig, null, 4)on the next line, so the option was silently ignored at runtime.