Skip to content

Bug: Incorrect return type from TSESLint.FlatESLint#calculateConfigForFile #11444

@Gajdascz

Description

@Gajdascz

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

https://stackblitz.com/edit/typescript-eslint-utils-type-err?file=index.ts

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 elements

ESLint 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:

/**
* 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

https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/utils/src/ts-eslint/ESLint.ts

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions