-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
tsconfig-utils
Playground Link
Repro Code
import { TSESLint } from '@typescript-eslint/utils';
const eslint = new TSESLint.FlatESLint({
overrideConfigFile: './eslint.config.js',
});
// The type here is FlatConfig.ConfigArray,
// but runtime result is a merged config object, not an array
const config = await eslint.calculateConfigForFile('index.ts');
console.log(Array.isArray(config)); // false
console.log(typeof config); // object
console.log(Object.keys(config)); // shows config fields, not array elementsESLint Config
tsconfig
Expected Result
The return type of TSESLint.FlatESLint#calculateConfigForFile() should be:
Promise<FlatConfig.Config>
This matches the ESLint Node.js API docs, which state that this method returns a resolved configuration object, not a config array.
Actual Result
Currently, the method is typed as returning:
Promise<FlatConfig.ConfigArray>
See source:
typescript-eslint/packages/utils/src/ts-eslint/eslint/FlatESLint.ts
Lines 14 to 21 in 12e6961
| /** | |
| * Returns a configuration object for the given file based on the CLI options. | |
| * This is the same logic used by the ESLint CLI executable to determine | |
| * configuration for each file it processes. | |
| * @param filePath The path of the file to retrieve a config object for. | |
| * @returns A configuration object for the file or `undefined` if there is no configuration data for the object. | |
| */ | |
| calculateConfigForFile(filePath: string): Promise<FlatConfig.ConfigArray>; |
This is incorrect, as calculateConfigForFile() returns a merged config object, not a config array.
Additional Info
This applies to all TSESLint ESLint wrapper classes in @typescript-eslint/utils, since they just alias a common base
If possible, I’d be happy to open a PR for this myself.
The fix would be to update the return type of FlatESLint#calculateConfigForFile from:
Promise<FlatConfig.ConfigArray>to:
Promise<FlatConfig.Config>Let me know if you're okay with that and I’ll proceed!
Versions
| package | version |
|---|---|
@typescript-eslint/utils |
8.38.0 |
TypeScript |
5.9.2 |
ESLint |
9.32.0 |
node |
22.14.0 |
typescript-eslint |
8.38.0 |