Skip to content

Commit

Permalink
Enable strictFunctionTypes (#49929)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Jan 18, 2023
1 parent 436833a commit 22b362c
Show file tree
Hide file tree
Showing 60 changed files with 1,257 additions and 863 deletions.
2 changes: 1 addition & 1 deletion src/compiler/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1163,7 +1163,7 @@ function convertToReusableCompilerOptionValue(option: CommandLineOption | undefi
if (option) {
Debug.assert(option.type !== "listOrElement");
if (option.type === "list") {
const values = value as readonly (string | number)[];
const values = value as readonly string[];
if (option.element.isFilePath && values.length) {
return values.map(relativeToBuildInfo);
}
Expand Down
79 changes: 42 additions & 37 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2880,7 +2880,7 @@ export function convertToOptionsWithAbsolutePaths(options: CompilerOptions, toAb
function convertToOptionValueWithAbsolutePaths(option: CommandLineOption | undefined, value: CompilerOptionsValue, toAbsolutePath: (path: string) => string) {
if (option && !isNullOrUndefined(value)) {
if (option.type === "list") {
const values = value as readonly (string | number)[];
const values = value as readonly string[];
if (option.element.isFilePath && values.length) {
return values.map(toAbsolutePath);
}
Expand Down Expand Up @@ -3846,7 +3846,8 @@ function validateSpecs(specs: readonly string[], errors: Push<Diagnostic>, disal
}
}

function specToDiagnostic(spec: string, disallowTrailingRecursion?: boolean): [DiagnosticMessage, string] | undefined {
function specToDiagnostic(spec: CompilerOptionsValue, disallowTrailingRecursion?: boolean): [DiagnosticMessage, string] | undefined {
Debug.assert(typeof spec === "string");
if (disallowTrailingRecursion && invalidTrailingRecursionPattern.test(spec)) {
return [Diagnostics.File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0, spec];
}
Expand Down
40 changes: 25 additions & 15 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ export function intersperse<T>(input: T[], element: T): T[] {
*
* @internal
*/
export function every<T, U extends T>(array: readonly T[], callback: (element: T, index: number) => element is U): array is readonly U[];
/** @internal */
export function every<T, U extends T>(array: readonly T[] | undefined, callback: (element: T, index: number) => element is U): array is readonly U[] | undefined;
/** @internal */
export function every<T>(array: readonly T[] | undefined, callback: (element: T, index: number) => boolean): boolean;
export function every<T>(array: readonly T[] | undefined, callback: (element: T, index: number) => boolean): boolean {
if (array) {
for (let i = 0; i < array.length; i++) {
Expand Down Expand Up @@ -478,7 +483,7 @@ export function sameFlatMap<T>(array: T[], mapfn: (x: T, i: number) => T | reado
/** @internal */
export function sameFlatMap<T>(array: readonly T[], mapfn: (x: T, i: number) => T | readonly T[]): readonly T[];
/** @internal */
export function sameFlatMap<T>(array: T[], mapfn: (x: T, i: number) => T | T[]): T[] {
export function sameFlatMap<T>(array: readonly T[], mapfn: (x: T, i: number) => T | readonly T[]): readonly T[] {
let result: T[] | undefined;
if (array) {
for (let i = 0; i < array.length; i++) {
Expand Down Expand Up @@ -703,11 +708,19 @@ export function concatenate<T>(array1: T[], array2: T[]): T[];
/** @internal */
export function concatenate<T>(array1: readonly T[], array2: readonly T[]): readonly T[];
/** @internal */
export function concatenate<T>(array1: T[] | undefined, array2: T[] | undefined): T[];
export function concatenate<T>(array1: T[], array2: T[] | undefined): T[]; // eslint-disable-line @typescript-eslint/unified-signatures
/** @internal */
export function concatenate<T>(array1: T[] | undefined, array2: T[]): T[]; // eslint-disable-line @typescript-eslint/unified-signatures
/** @internal */
export function concatenate<T>(array1: readonly T[], array2: readonly T[] | undefined): readonly T[]; // eslint-disable-line @typescript-eslint/unified-signatures
/** @internal */
export function concatenate<T>(array1: readonly T[] | undefined, array2: readonly T[]): readonly T[]; // eslint-disable-line @typescript-eslint/unified-signatures
/** @internal */
export function concatenate<T>(array1: readonly T[] | undefined, array2: readonly T[] | undefined): readonly T[];
export function concatenate<T>(array1: T[] | undefined, array2: T[] | undefined): T[] | undefined;
/** @internal */
export function concatenate<T>(array1: T[], array2: T[]): T[] {
export function concatenate<T>(array1: readonly T[] | undefined, array2: readonly T[] | undefined): readonly T[] | undefined;
/** @internal */
export function concatenate<T>(array1: readonly T[] | undefined, array2: readonly T[] | undefined): readonly T[] | undefined {
if (!some(array2)) return array1;
if (!some(array1)) return array2;
return [...array1, ...array2];
Expand Down Expand Up @@ -856,7 +869,7 @@ export function detectSortCaseSensitivity(array: readonly string[], useEslintOrd
/** @internal */
export function detectSortCaseSensitivity<T>(array: readonly T[], useEslintOrdering: boolean, getString: (element: T) => string): SortKind;
/** @internal */
export function detectSortCaseSensitivity<T>(array: readonly T[], useEslintOrdering: boolean, getString?: (element: T) => string): SortKind {
export function detectSortCaseSensitivity<T>(array: readonly T[], useEslintOrdering?: boolean, getString?: (element: T) => string): SortKind {
let kind = SortKind.Both;
if (array.length < 2) return kind;
const caseSensitiveComparer = getString
Expand Down Expand Up @@ -915,7 +928,7 @@ export function compact<T>(array: T[]): T[]; // eslint-disable-line @typescript-
/** @internal */
export function compact<T>(array: readonly T[]): readonly T[]; // eslint-disable-line @typescript-eslint/unified-signatures
/** @internal */
export function compact<T>(array: T[]): T[] {
export function compact<T>(array: readonly T[]): readonly T[] {
let result: T[] | undefined;
if (array) {
for (let i = 0; i < array.length; i++) {
Expand Down Expand Up @@ -998,11 +1011,12 @@ export function append<T>(to: T[] | undefined, value: T | undefined): T[] | unde
/** @internal */
export function append<T>(to: Push<T>, value: T | undefined): void;
/** @internal */
export function append<T>(to: T[], value: T | undefined): T[] | undefined {
if (value === undefined) return to;
export function append<T>(to: Push<T> | T[] | undefined, value: T | undefined): T[] | undefined {
// If to is Push<T>, return value is void, so safe to cast to T[].
if (value === undefined) return to as T[];
if (to === undefined) return [value];
to.push(value);
return to;
return to as T[];
}

/**
Expand Down Expand Up @@ -1315,7 +1329,7 @@ export function reduceLeft<T, U>(array: readonly T[] | undefined, f: (memo: U, v
/** @internal */
export function reduceLeft<T>(array: readonly T[], f: (memo: T, value: T, i: number) => T): T | undefined;
/** @internal */
export function reduceLeft<T>(array: T[], f: (memo: T, value: T, i: number) => T, initial?: T, start?: number, count?: number): T | undefined {
export function reduceLeft<T>(array: readonly T[] | undefined, f: (memo: T, value: T, i: number) => T, initial?: T, start?: number, count?: number): T | undefined {
if (array && array.length > 0) {
const size = array.length;
if (size > 0) {
Expand Down Expand Up @@ -1867,11 +1881,7 @@ export function isNumber(x: unknown): x is number {
}

/** @internal */
export function tryCast<TOut extends TIn, TIn = any>(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut | undefined;
/** @internal */
export function tryCast<T>(value: T, test: (value: T) => boolean): T | undefined;
/** @internal */
export function tryCast<T>(value: T, test: (value: T) => boolean): T | undefined {
export function tryCast<TOut extends TIn, TIn = any>(value: TIn | undefined, test: (value: TIn) => value is TOut): TOut | undefined {
return value !== undefined && test(value) ? value : undefined;
}

Expand Down
6 changes: 3 additions & 3 deletions src/compiler/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,13 @@ export namespace Debug {
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[];
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;
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;
export function assertEachNode(nodes: readonly Node[], test: (node: Node) => boolean, message?: string, stackCrawlMark?: AnyFunction): void;
export function assertEachNode(nodes: readonly Node[] | undefined, test: (node: Node) => boolean, message?: string, stackCrawlMark?: AnyFunction) {
export function assertEachNode(nodes: readonly Node[], test: ((node: Node) => boolean) | undefined, message?: string, stackCrawlMark?: AnyFunction): void;
export function assertEachNode(nodes: readonly Node[] | undefined, test: ((node: Node) => boolean) | undefined, message?: string, stackCrawlMark?: AnyFunction) {
if (shouldAssertFunction(AssertionLevel.Normal, "assertEachNode")) {
assert(
test === undefined || every(nodes, test),
message || "Unexpected node.",
() => `Node array did not pass test '${getFunctionName(test)}'.`,
() => `Node array did not pass test '${getFunctionName(test!)}'.`,
stackCrawlMark || assertEachNode);
}
}
Expand Down
Loading

0 comments on commit 22b362c

Please sign in to comment.