8000 feat(typescript-estree): make withoutProjectParserOptions generic (#9… · abrahamguo/typescript-eslint@c27b9e9 · GitHub
[go: up one dir, main page]

Skip to content

Commit c27b9e9

Browse files
feat(typescript-estree): make withoutProjectParserOptions generic (typescript-eslint#9877)
* feat(typescript-estree): make withoutProjectParserOptions generic * Update packages/typescript-estree/src/withoutProjectParserOptions.ts Co-authored-by: Brad Zacher <brad.zacher@gmail.com> * Remove unnecessary import --------- Co-authored-by: Brad Zacher <brad.zacher@gmail.com>
1 parent cc50e62 commit c27b9e9

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { TSESTreeOptions } from './parser-options';
2-
31
/**
42
* Removes options that prompt the parser to parse the project with type
53
* information. In other words, you can use this if you are invoking the parser
@@ -8,12 +6,15 @@ import type { TSESTreeOptions } from './parser-options';
86
*
97
* @see https://github.com/typescript-eslint/typescript-eslint/issues/8428
108
*/
11-
export function withoutProjectParserOptions(
12-
opts: TSESTreeOptions,
13-
): TSESTreeOptions {
9+
export function withoutProjectParserOptions<Options extends object>(
10+
opts: Options,
11+
): Omit<
12+
Options,
13+
'EXPERIMENTAL_useProjectService' | 'project' | 'projectService'
14+
> {
1415
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- The variables are meant to be omitted
1516
const { EXPERIMENTAL_useProjectService, project, projectService, ...rest } =
1617
opts as Record<string, unknown>;
1718

18-
return rest;
19+
return rest as unknown as Options;
1920
}

packages/typescript-estree/tests/lib/withoutProjectParserOptions.test.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,31 @@ import { withoutProjectParserOptions } from '../../src';
33

44
describe('withoutProjectParserOptions', () => {
55
it('removes only project parser options', () => {
6-
const without = without 8000 ProjectParserOptions({
6+
const options = {
77
comment: true,
88
EXPERIMENTAL_useProjectService: true,
99
project: true,
1010
projectService: true,
11-
} as TSESTreeOptions);
11+
} as TSESTreeOptions;
12+
13+
const without = withoutProjectParserOptions(options);
14+
15+
expect(without).toEqual({
16+
comment: true,
17+
});
18+
});
19+
20+
it('allows an alternate type extending from TSESTreeOptions', () => {
21+
const without = withoutProjectParserOptions({
22+
comment: true,
23+
project: true,
24+
projectService: true,
25+
other: true,
26+
});
27+
1228
expect(without).toEqual({
1329
comment: true,
30+
other: true,
1431
});
1532
});
1633
});

0 commit comments

Comments
 (0)
0