Skip to content

Commit 22b362c

Browse files
authored
Enable strictFunctionTypes (#49929)
1 parent 436833a commit 22b362c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1257
-863
lines changed

src/compiler/builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ function convertToReusableCompilerOptionValue(option: CommandLineOption | undefi
11631163
if (option) {
11641164
Debug.assert(option.type !== "listOrElement");
11651165
if (option.type === "list") {
1166-
const values = value as readonly (string | number)[];
1166+
const values = value as readonly string[];
11671167
if (option.element.isFilePath && values.length) {
11681168
return values.map(relativeToBuildInfo);
11691169
}

src/compiler/checker.ts

Lines changed: 42 additions & 37 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2880,7 +2880,7 @@ export function convertToOptionsWithAbsolutePaths(options: CompilerOptions, toAb
28802880
function convertToOptionValueWithAbsolutePaths(option: CommandLineOption | undefined, value: CompilerOptionsValue, toAbsolutePath: (path: string) => string) {
28812881
if (option && !isNullOrUndefined(value)) {
28822882
if (option.type === "list") {
2883-
const values = value as readonly (string | number)[];
2883+
const values = value as readonly string[];
28842884
if (option.element.isFilePath && values.length) {
28852885
return values.map(toAbsolutePath);
28862886
}
@@ -3846,7 +3846,8 @@ function validateSpecs(specs: readonly string[], errors: Push<Diagnostic>, disal
38463846
}
38473847
}
38483848

3849-
function specToDiagnostic(spec: string, disallowTrailingRecursion?: boolean): [DiagnosticMessage, string] | undefined {
3849+
function specToDiagnostic(spec: CompilerOptionsValue, disallowTrailingRecursion?: boolean): [DiagnosticMessage, string] | undefined {
3850+
Debug.assert(typeof spec === "string");
38503851
if (disallowTrailingRecursion && invalidTrailingRecursionPattern.test(spec)) {
38513852
return [Diagnostics.File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0, spec];
38523853
}

src/compiler/core.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ export function intersperse<T>(input: T[], element: T): T[] {
142142
*
143143
* @internal
144144
*/
145+
export function every<T, U extends T>(array: readonly T[], callback: (element: T, index: number) => element is U): array is readonly U[];
146+
/** @internal */
147+
export function every<T, U extends T>(array: readonly T[] | undefined, callback: (element: T, index: number) => element is U): array is readonly U[] | undefined;
148+
/** @internal */
149+
export function every<T>(array: readonly T[] | undefined, callback: (element: T, index: number) => boolean): boolean;
145150
export function every<T>(array: readonly T[] | undefined, callback: (element: T, index: number) => boolean): boolean {
146151
if (array) {
147152
for (let i = 0; i < array.length; i++) {
@@ -478,7 +483,7 @@ export function sameFlatMap<T>(array: T[], mapfn: (x: T, i: number) => T | reado
478483
/** @internal */
479484
export function sameFlatMap<T>(array: readonly T[], mapfn: (x: T, i: number) => T | readonly T[]): readonly T[];
480485
/** @internal */
481-
export function sameFlatMap<T>(array: T[], mapfn: (x: T, i: number) => T | T[]): T[] {
486+
export function sameFlatMap<T>(array: readonly T[], mapfn: (x: T, i: number) => T | readonly T[]): readonly T[] {
482487
let result: T[] | undefined;
483488
if (array) {
484489
for (let i = 0; i < array.length; i++) {
@@ -703,11 +708,19 @@ export function concatenate<T>(array1: T[], array2: T[]): T[];
703708
/** @internal */
704709
export function concatenate<T>(array1: readonly T[], array2: readonly T[]): readonly T[];
705710
/** @internal */
706-
export function concatenate<T>(array1: T[] | undefined, array2: T[] | undefined): T[];
711+
export function concatenate<T>(array1: T[], array2: T[] | undefined): T[]; // eslint-disable-line @typescript-eslint/unified-signatures
712+
/** @internal */
713+
export function concatenate<T>(array1: T[] | undefined, array2: T[]): T[]; // eslint-disable-line @typescript-eslint/unified-signatures
714+
/** @internal */
715+
export function concatenate<T>(array1: readonly T[], array2: readonly T[] | undefined): readonly T[]; // eslint-disable-line @typescript-eslint/unified-signatures
716+
/** @internal */
717+
export function concatenate<T>(array1: readonly T[] | undefined, array2: readonly T[]): readonly T[]; // eslint-disable-line @typescript-eslint/unified-signatures
707718
/** @internal */
708-
export function concatenate<T>(array1: readonly T[] | undefined, array2: readonly T[] | undefined): readonly T[];
719+
export function concatenate<T>(array1: T[] | undefined, array2: T[] | undefined): T[] | undefined;
709720
/** @internal */
710-
export function concatenate<T>(array1: T[], array2: T[]): T[] {
721+
export function concatenate<T>(array1: readonly T[] | undefined, array2: readonly T[] | undefined): readonly T[] | undefined;
722+
/** @internal */
723+
export function concatenate<T>(array1: readonly T[] | undefined, array2: readonly T[] | undefined): readonly T[] | undefined {
711724
if (!some(array2)) return array1;
712725
if (!some(array1)) return array2;
713726
return [...array1, ...array2];
@@ -856,7 +869,7 @@ export function detectSortCaseSensitivity(array: readonly string[], useEslintOrd
856869
/** @internal */
857870
export function detectSortCaseSensitivity<T>(array: readonly T[], useEslintOrdering: boolean, getString: (element: T) => string): SortKind;
858871
/** @internal */
859-
export function detectSortCaseSensitivity<T>(array: readonly T[], useEslintOrdering: boolean, getString?: (element: T) => string): SortKind {
872+
export function detectSortCaseSensitivity<T>(array: readonly T[], useEslintOrdering?: boolean, getString?: (element: T) => string): SortKind {
860873
let kind = SortKind.Both;
861874
if (array.length < 2) return kind;
862875
const caseSensitiveComparer = getString
@@ -915,7 +928,7 @@ export function compact<T>(array: T[]): T[]; // eslint-disable-line @typescript-
915928
/** @internal */
916929
export function compact<T>(array: readonly T[]): readonly T[]; // eslint-disable-line @typescript-eslint/unified-signatures
917930
/** @internal */
918-
export function compact<T>(array: T[]): T[] {
931+
export function compact<T>(array: readonly T[]): readonly T[] {
919932
let result: T[] | undefined;
920933
if (array) {
921934
for (let i = 0; i < array.length; i++) {
@@ -998,11 +1011,12 @@ export function append<T>(to: T[] | undefined, value: T | undefined): T[] | unde
9981011
/** @internal */
9991012
export function append<T>(to: Push<T>, value: T | undefined): void;
10001013
/** @internal */
1001-
export function append<T>(to: T[], value: T | undefined): T[] | undefined {
1002-
if (value === undefined) return to;
1014+
export function append<T>(to: Push<T> | T[] | undefined, value: T | undefined): T[] | undefined {
1015+
// If to is Push<T>, return value is void, so safe to cast to T[].
1016+
if (value === undefined) return to as T[];
10031017
if (to === undefined) return [value];
10041018
to.push(value);
1005-
return to;
1019+
return to as T[];
10061020
}
10071021

10081022
/**
@@ -1315,7 +1329,7 @@ export function reduceLeft<T, U>(array: readonly T[] | undefined, f: (memo: U, v
13151329
/** @internal */
13161330
export function reduceLeft<T>(array: readonly T[], f: (memo: T, value: T, i: number) => T): T | undefined;
13171331
/** @internal */
1318-
export function reduceLeft<T>(array: T[], f: (memo: T, value: T, i: number) => T, initial?: T, start?: number, count?: number): T | undefined {
1332+
export function reduceLeft<T>(array: readonly T[] | undefined, f: (memo: T, value: T, i: number) => T, initial?: T, start?: number, count?: number): T | undefined {
13191333
if (array && array.length > 0) {
13201334
const size = array.length;
13211335
if (size > 0) {
@@ -1867,11 +1881,7 @@ export function isNumber(x: unknown): x is number {
18671881
}
18681882

18691883
/** @internal */
1870-
export function tryCast<TOut extends TIn, TIn = any>(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut | undefined;
1871-
/** @internal */
1872-
export function tryCast<T>(value: T, test: (value: T) => boolean): T | undefined;
1873-
/** @internal */
1874-
export function tryCast<T>(value: T, test: (value: T) => boolean): T | undefined {
1884+
export function tryCast<TOut extends TIn, TIn = any>(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut | undefined {
18751885
return value !== undefined && test(value) ? value : undefined;
18761886
}
18771887

src/compiler/debug.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@ export namespace Debug {
275275
export function assertEachNode<T extends Node, U extends T>(nodes: readonly T[], test: (node: T) => node is U, message?: string, stackCrawlMark?: AnyFunction): asserts nodes is readonly U[];
276276
export function assertEachNode<T extends Node, U extends T>(nodes: NodeArray<T> | undefined, test: (node: T) => node is U, message?: string, stackCrawlMark?: AnyFunction): asserts nodes is NodeArray<U> | undefined;
277277
export function assertEachNode<T extends Node, U extends T>(nodes: readonly T[] | undefined, test: (node: T) => node is U, message?: string, stackCrawlMark?: AnyFunction): asserts nodes is readonly U[] | undefined;
278-
export function assertEachNode(nodes: readonly Node[], test: (node: Node) => boolean, message?: string, stackCrawlMark?: AnyFunction): void;
279-
export function assertEachNode(nodes: readonly Node[] | undefined, test: (node: Node) => boolean, message?: string, stackCrawlMark?: AnyFunction) {
278+
export function assertEachNode(nodes: readonly Node[], test: ((node: Node) => boolean) | undefined, message?: string, stackCrawlMark?: AnyFunction): void;
279+
export function assertEachNode(nodes: readonly Node[] | undefined, test: ((node: Node) => boolean) | undefined, message?: string, stackCrawlMark?: AnyFunction) {
280280
if (shouldAssertFunction(AssertionLevel.Normal, "assertEachNode")) {
281281
assert(
282282
test === undefined || every(nodes, test),
283283
message || "Unexpected node.",
284-
() => `Node array did not pass test '${getFunctionName(test)}'.`,
284+
() => `Node array did not pass test '${getFunctionName(test!)}'.`,
285285
stackCrawlMark || assertEachNode);
286286
}
287287
}

0 commit comments

Comments
 (0)