diff --git a/packages/typescript-estree/src/withoutProjectParserOptions.ts b/packages/typescript-estree/src/withoutProjectParserOptions.ts index a58074f50361..a6a8a97f61d6 100644 --- a/packages/typescript-estree/src/withoutProjectParserOptions.ts +++ b/packages/typescript-estree/src/withoutProjectParserOptions.ts @@ -1,5 +1,3 @@ -import type { TSESTreeOptions } from './parser-options'; - /** * Removes options that prompt the parser to parse the project with type * information. In other words, you can use this if you are invoking the parser @@ -8,12 +6,15 @@ import type { TSESTreeOptions } from './parser-options'; * * @see https://github.com/typescript-eslint/typescript-eslint/issues/8428 */ -export function withoutProjectParserOptions( - opts: TSESTreeOptions, -): TSESTreeOptions { +export function withoutProjectParserOptions( + opts: Options, +): Omit< + Options, + 'EXPERIMENTAL_useProjectService' | 'project' | 'projectService' +> { // eslint-disable-next-line @typescript-eslint/no-unused-vars -- The variables are meant to be omitted const { EXPERIMENTAL_useProjectService, project, projectService, ...rest } = opts as Record; - return rest; + return rest as unknown as Options; } diff --git a/packages/typescript-estree/tests/lib/withoutProjectParserOptions.test.ts b/packages/typescript-estree/tests/lib/withoutProjectParserOptions.test.ts index 9a7468f19dff..bf1b111544da 100644 --- a/packages/typescript-estree/tests/lib/withoutProjectParserOptions.test.ts +++ b/packages/typescript-estree/tests/lib/withoutProjectParserOptions.test.ts @@ -3,14 +3,31 @@ import { withoutProjectParserOptions } from '../../src'; describe('withoutProjectParserOptions', () => { it('removes only project parser options', () => { - const without = withoutProjectParserOptions({ + const options = { comment: true, EXPERIMENTAL_useProjectService: true, project: true, projectService: true, - } as TSESTreeOptions); + } as TSESTreeOptions; + + const without = withoutProjectParserOptions(options); + + expect(without).toEqual({ + comment: true, + }); + }); + + it('allows an alternate type extending from TSESTreeOptions', () => { + const without = withoutProjectParserOptions({ + comment: true, + project: true, + projectService: true, + other: true, + }); + expect(without).toEqual({ comment: true, + other: true, }); }); });