From dc97890ba1a2d26b32ca436be70160c83d94587b Mon Sep 17 00:00:00 2001 From: graphemecluster Date: Fri, 14 Oct 2022 09:41:35 +0800 Subject: [PATCH] Another Attempt --- src/lib/es2015.iterable.d.ts | 18 +-- src/lib/es5.d.ts | 18 +-- .../arrayDestructuringInSwitch1.types | 4 +- .../reference/arrayTypeOfTypeOf.types | 4 +- ...InternalTypesProduceUniqueTypeParams.types | 4 +- .../reference/fixSignatureCaching.types | 4 +- .../reference/instantiationExpressions.types | 12 +- tests/baselines/reference/isArray.types | 4 +- .../baselines/reference/isArrayConformance.js | 8 +- .../reference/isArrayConformance.symbols | 4 +- .../reference/isArrayConformance.types | 56 ++++---- .../reference/isArrayConformance2.js | 41 ++++++ .../reference/isArrayConformance2.symbols | 90 ++++++++++++ .../reference/isArrayConformance2.types | 134 +++++++++++++++--- ...riptThisAssignmentInStaticBlock.errors.txt | 8 +- ...avascriptThisAssignmentInStaticBlock.types | 8 +- ...teralFreshnessPropagationOnNarrowing.types | 8 +- tests/baselines/reference/malformedTags.types | 4 +- ...gAssignmentReadonlyRespectsAssertion.types | 4 +- .../noIterationTypeErrorsInCFA.types | 4 +- tests/baselines/reference/parserharness.types | 8 +- .../partiallyDiscriminantedUnions.types | 4 +- .../spreadBooleanRespectsFreshness.types | 4 +- .../reference/unknownControlFlow.types | 8 +- tests/cases/compiler/isArrayConformance.ts | 4 +- tests/cases/compiler/isArrayConformance2.ts | 20 +++ 26 files changed, 365 insertions(+), 120 deletions(-) diff --git a/src/lib/es2015.iterable.d.ts b/src/lib/es2015.iterable.d.ts index f7e9ae85ceec0..35dfffe991670 100644 --- a/src/lib/es2015.iterable.d.ts +++ b/src/lib/es2015.iterable.d.ts @@ -57,18 +57,18 @@ interface Array { interface ArrayConstructor { isArray(arg: T): arg is - T extends any ? Extract< + T extends any ? ( - true extends false & T ? any : - T extends string | readonly any[] ? unknown : - T extends ArrayLike | Iterable ? U : - unknown - )[] | ( + true extends false & T ? Extract : + T extends string | readonly any[] ? never : + T extends ArrayLike | Iterable ? Extract : + never + ) | ( true extends false & T ? never : - {} extends T ? T & unknown[] : + {} extends Required ? T & any[] : Extract - ), T - > : never; + ) + : never; /** * Creates an array from an iterable object. diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index 794a45daae5f1..4f82ad78f1135 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1469,18 +1469,18 @@ interface ArrayConstructor { (arrayLength: number): T[]; (...items: T[]): T[]; isArray(arg: T): arg is - T extends any ? Extract< + T extends any ? ( - true extends false & T ? any : - T extends string | readonly any[] ? unknown : - T extends ArrayLike ? U : - unknown - )[] | ( + true extends false & T ? Extract : + T extends string | readonly any[] ? never : + T extends ArrayLike ? Extract : + never + ) | ( true extends false & T ? never : - {} extends T ? T & unknown[] : + {} extends Required ? T & any[] : Extract - ), T - > : never; + ) + : never; readonly prototype: any[]; } diff --git a/tests/baselines/reference/arrayDestructuringInSwitch1.types b/tests/baselines/reference/arrayDestructuringInSwitch1.types index 592e0a19badb9..2bf90094e06fd 100644 --- a/tests/baselines/reference/arrayDestructuringInSwitch1.types +++ b/tests/baselines/reference/arrayDestructuringInSwitch1.types @@ -11,9 +11,9 @@ export function evaluate(expression: Expression): boolean { if (Array.isArray(expression)) { >Array.isArray(expression) : boolean ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >expression : Expression const [operator, ...operands] = expression; diff --git a/tests/baselines/reference/arrayTypeOfTypeOf.types b/tests/baselines/reference/arrayTypeOfTypeOf.types index 0185c4d1e4716..06aa6bf7ff069 100644 --- a/tests/baselines/reference/arrayTypeOfTypeOf.types +++ b/tests/baselines/reference/arrayTypeOfTypeOf.types @@ -14,11 +14,11 @@ var xs2: typeof Array; >Array : ArrayConstructor var xs3: typeof Array; ->xs3 : { (arrayLength: number): number[]; (...items: number[]): number[]; new (arrayLength: number): number[]; new (...items: number[]): number[]; isArray(arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; readonly prototype: any[]; } +>xs3 : { (arrayLength: number): number[]; (...items: number[]): number[]; new (arrayLength: number): number[]; new (...items: number[]): number[]; isArray(arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; readonly prototype: any[]; } >Array : ArrayConstructor var xs4: typeof Array; ->xs4 : { (arrayLength: number): number[]; (...items: number[]): number[]; new (arrayLength: number): number[]; new (...items: number[]): number[]; isArray(arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; readonly prototype: any[]; } +>xs4 : { (arrayLength: number): number[]; (...items: number[]): number[]; new (arrayLength: number): number[]; new (...items: number[]): number[]; isArray(arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; readonly prototype: any[]; } >Array : ArrayConstructor >x : number diff --git a/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types b/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types index 3eec3dcb5f101..7c963a7e36ab3 100644 --- a/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types +++ b/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types @@ -67,9 +67,9 @@ export const updateIfChanged = (t: T) => { >assign : { (target: T, source: U): T & U; (target: T, source1: U, source2: V): T & U & V; (target: T, source1: U, source2: V, source3: W): T & U & V & W; (target: object, ...sources: any[]): any; } >Array.isArray(u) ? [] : {} : undefined[] | {} >Array.isArray(u) : boolean ->Array.isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>Array.isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >Array : ArrayConstructor ->isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >u : U >[] : undefined[] >{} : {} diff --git a/tests/baselines/reference/fixSignatureCaching.types b/tests/baselines/reference/fixSignatureCaching.types index c53fef53265d7..340be93100909 100644 --- a/tests/baselines/reference/fixSignatureCaching.types +++ b/tests/baselines/reference/fixSignatureCaching.types @@ -1109,9 +1109,9 @@ define(function () { >Array : ArrayConstructor Array.isArray : function (value) { return Object.prototype.toString.call(value) === '[object Array]'; }; ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >function (value) { return Object.prototype.toString.call(value) === '[object Array]'; } : (value: any) => boolean >value : any >Object.prototype.toString.call(value) === '[object Array]' : boolean diff --git a/tests/baselines/reference/instantiationExpressions.types b/tests/baselines/reference/instantiationExpressions.types index ae0c783319efc..dca0c32382e77 100644 --- a/tests/baselines/reference/instantiationExpressions.types +++ b/tests/baselines/reference/instantiationExpressions.types @@ -61,13 +61,13 @@ function f2() { >Array : ArrayConstructor const A1 = Array; // new (...) => string[] ->A1 : { (arrayLength: number): string[]; (...items: string[]): string[]; new (arrayLength: number): string[]; new (...items: string[]): string[]; isArray(arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; readonly prototype: any[]; } ->Array : { (arrayLength: number): string[]; (...items: string[]): string[]; new (arrayLength: number): string[]; new (...items: string[]): string[]; isArray(arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; readonly prototype: any[]; } +>A1 : { (arrayLength: number): string[]; (...items: string[]): string[]; new (arrayLength: number): string[]; new (...items: string[]): string[]; isArray(arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; readonly prototype: any[]; } +>Array : { (arrayLength: number): string[]; (...items: string[]): string[]; new (arrayLength: number): string[]; new (...items: string[]): string[]; isArray(arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; readonly prototype: any[]; } >Array : ArrayConstructor const A2 = Array; // Error ->A2 : { isArray(arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; readonly prototype: any[]; } ->Array : { isArray(arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; readonly prototype: any[]; } +>A2 : { isArray(arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; readonly prototype: any[]; } +>Array : { isArray(arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; readonly prototype: any[]; } >Array : ArrayConstructor } @@ -76,11 +76,11 @@ type T20 = typeof Array<>; // Error >Array : ArrayConstructor type T21 = typeof Array; // new (...) => string[] ->T21 : { (arrayLength: number): string[]; (...items: string[]): string[]; new (arrayLength: number): string[]; new (...items: string[]): string[]; isArray(arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; readonly prototype: any[]; } +>T21 : { (arrayLength: number): string[]; (...items: string[]): string[]; new (arrayLength: number): string[]; new (...items: string[]): string[]; isArray(arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; readonly prototype: any[]; } >Array : ArrayConstructor type T22 = typeof Array; // Error ->T22 : { isArray(arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; readonly prototype: any[]; } +>T22 : { isArray(arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; readonly prototype: any[]; } >Array : ArrayConstructor declare class C { diff --git a/tests/baselines/reference/isArray.types b/tests/baselines/reference/isArray.types index 3fc88f4d2fcca..ba56644f4843e 100644 --- a/tests/baselines/reference/isArray.types +++ b/tests/baselines/reference/isArray.types @@ -5,9 +5,9 @@ var maybeArray: number | number[]; if (Array.isArray(maybeArray)) { >Array.isArray(maybeArray) : boolean ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >maybeArray : number | number[] maybeArray.length; // OK diff --git a/tests/baselines/reference/isArrayConformance.js b/tests/baselines/reference/isArrayConformance.js index e9d7201dce498..b71fcd5ea35f7 100644 --- a/tests/baselines/reference/isArrayConformance.js +++ b/tests/baselines/reference/isArrayConformance.js @@ -7,7 +7,7 @@ function f1(a: any) { function f2(a: unknown) { if (Array.isArray(a)) { - a; // Expected: unknown[] + a; // Expected: any[] } } @@ -39,7 +39,7 @@ function f6(a: (number[] | null | "loading")[]) { function f7(a: {} | null) { if (Array.isArray(a)) { - a; // Expected: unknown[] + a; // Expected: any[] } } @@ -65,7 +65,7 @@ function f1(a) { } function f2(a) { if (Array.isArray(a)) { - a; // Expected: unknown[] + a; // Expected: any[] } } function f3(a) { @@ -91,7 +91,7 @@ function f6(a) { } function f7(a) { if (Array.isArray(a)) { - a; // Expected: unknown[] + a; // Expected: any[] } } function f8(a) { diff --git a/tests/baselines/reference/isArrayConformance.symbols b/tests/baselines/reference/isArrayConformance.symbols index e7152164c5337..d634dda2aedda 100644 --- a/tests/baselines/reference/isArrayConformance.symbols +++ b/tests/baselines/reference/isArrayConformance.symbols @@ -24,7 +24,7 @@ function f2(a: unknown) { >isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) >a : Symbol(a, Decl(isArrayConformance.ts, 6, 12)) - a; // Expected: unknown[] + a; // Expected: any[] >a : Symbol(a, Decl(isArrayConformance.ts, 6, 12)) } } @@ -111,7 +111,7 @@ function f7(a: {} | null) { >isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) >a : Symbol(a, Decl(isArrayConformance.ts, 38, 12)) - a; // Expected: unknown[] + a; // Expected: any[] >a : Symbol(a, Decl(isArrayConformance.ts, 38, 12)) } } diff --git a/tests/baselines/reference/isArrayConformance.types b/tests/baselines/reference/isArrayConformance.types index 7146606318faf..8b2db137a2323 100644 --- a/tests/baselines/reference/isArrayConformance.types +++ b/tests/baselines/reference/isArrayConformance.types @@ -5,9 +5,9 @@ function f1(a: any) { if (Array.isArray(a)) { >Array.isArray(a) : boolean ->Array.isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>Array.isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >Array : ArrayConstructor ->isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >a : any a; // Expected: any[] @@ -21,13 +21,13 @@ function f2(a: unknown) { if (Array.isArray(a)) { >Array.isArray(a) : boolean ->Array.isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>Array.isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >Array : ArrayConstructor ->isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >a : unknown - a; // Expected: unknown[] ->a : unknown[] + a; // Expected: any[] +>a : any[] } } @@ -37,9 +37,9 @@ function f3(a: string | readonly string[] | number[]) { if (Array.isArray(a)) { >Array.isArray(a) : boolean ->Array.isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>Array.isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >Array : ArrayConstructor ->isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >a : string | readonly string[] | number[] var b: readonly string[] | number[] = a; // OK @@ -59,18 +59,18 @@ function f4(a: T) { if (Array.isArray(a)) { >Array.isArray(a) : boolean ->Array.isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>Array.isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >Array : ArrayConstructor ->isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >a : T var b: readonly string[] | number[] = a; // OK >b : readonly string[] | number[] ->a : T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never +>a : T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never a[0]; // Expected: string | number >a[0] : string | number ->a : T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never +>a : T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >0 : 0 } } @@ -83,14 +83,14 @@ function f5(a: T) { if (Array.isArray(a)) { >Array.isArray(a) : boolean ->Array.isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>Array.isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >Array : ArrayConstructor ->isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >a : T a[0]; // Expected: string >a[0] : string ->a : T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never +>a : T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >0 : 0 } } @@ -101,13 +101,13 @@ function f6(a: (number[] | null | "loading")[]) { >null : null a.filter(Array.isArray); // Expected: number[][] ->a.filter(Array.isArray) : (number[] | "loading")[] +>a.filter(Array.isArray) : any[][] >a.filter : { (predicate: (value: number[] | "loading", index: number, array: (number[] | "loading")[]) => value is S, thisArg?: any): S[]; (predicate: (value: number[] | "loading", index: number, array: (number[] | "loading")[]) => unknown, thisArg?: any): (number[] | "loading")[]; } >a : (number[] | "loading")[] >filter : { (predicate: (value: number[] | "loading", index: number, array: (number[] | "loading")[]) => value is S, thisArg?: any): S[]; (predicate: (value: number[] | "loading", index: number, array: (number[] | "loading")[]) => unknown, thisArg?: any): (number[] | "loading")[]; } ->Array.isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>Array.isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >Array : ArrayConstructor ->isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } } function f7(a: {} | null) { @@ -117,13 +117,13 @@ function f7(a: {} | null) { if (Array.isArray(a)) { >Array.isArray(a) : boolean ->Array.isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>Array.isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >Array : ArrayConstructor ->isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >a : {} - a; // Expected: unknown[] ->a : unknown[] + a; // Expected: any[] +>a : any[] } } @@ -134,18 +134,18 @@ function f8 | Iterable | readonly string[] if (Array.isArray(a)) { >Array.isArray(a) : boolean ->Array.isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>Array.isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >Array : ArrayConstructor ->isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >a : T var b: readonly string[] | number[] | boolean[] = a; // OK >b : readonly string[] | number[] | boolean[] ->a : T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never +>a : T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never a[0]; // Expected: string | number | boolean >a[0] : string | number | boolean ->a : T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never +>a : T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >0 : 0 } } @@ -157,9 +157,9 @@ function f9(a: number | null) { if (Array.isArray(a)) { >Array.isArray(a) : boolean ->Array.isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>Array.isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >Array : ArrayConstructor ->isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >a : number a; // Expected: never diff --git a/tests/baselines/reference/isArrayConformance2.js b/tests/baselines/reference/isArrayConformance2.js index 2b0d74b929a3a..bb73838def727 100644 --- a/tests/baselines/reference/isArrayConformance2.js +++ b/tests/baselines/reference/isArrayConformance2.js @@ -35,6 +35,26 @@ function fe(data: T) { } } } + +function ff(a: T | T[]): T[] { + return Array.isArray(a) ? a : [a]; // OK +} + +function fg(arr1: T[], arr2: T[]) { + for (let i = 0; i < arr1.length && i < arr2.length; i++) { + const item1 = arr1[i]; + const item2 = arr2[i]; + if (Array.isArray(item1) && Array.isArray(item2)) { + fg(item1, item2); // OK + } + } +} + +function fh(...args: [] | [attributes: ({ $: string } & Partial>) | Record, children?: any[]] | [children: any[]]) { + if (Array.isArray(args[0])) { + const children: (Record | HTMLElement)[] = args[0]; // OK + } +} //// [isArrayConformance2.js] @@ -70,3 +90,24 @@ function fe(data) { } } } +function ff(a) { + return Array.isArray(a) ? a : [a]; // OK +} +function fg(arr1, arr2) { + for (var i = 0; i < arr1.length && i < arr2.length; i++) { + var item1 = arr1[i]; + var item2 = arr2[i]; + if (Array.isArray(item1) && Array.isArray(item2)) { + fg(item1, item2); // OK + } + } +} +function fh() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + if (Array.isArray(args[0])) { + var children = args[0]; // OK + } +} diff --git a/tests/baselines/reference/isArrayConformance2.symbols b/tests/baselines/reference/isArrayConformance2.symbols index 4264fcb6e5a2d..e5c0f2cfa1eef 100644 --- a/tests/baselines/reference/isArrayConformance2.symbols +++ b/tests/baselines/reference/isArrayConformance2.symbols @@ -118,3 +118,93 @@ function fe(data: T) { } } +function ff(a: T | T[]): T[] { +>ff : Symbol(ff, Decl(isArrayConformance2.ts, 35, 1)) +>T : Symbol(T, Decl(isArrayConformance2.ts, 37, 12)) +>a : Symbol(a, Decl(isArrayConformance2.ts, 37, 27)) +>T : Symbol(T, Decl(isArrayConformance2.ts, 37, 12)) +>T : Symbol(T, Decl(isArrayConformance2.ts, 37, 12)) +>T : Symbol(T, Decl(isArrayConformance2.ts, 37, 12)) + + return Array.isArray(a) ? a : [a]; // OK +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>a : Symbol(a, Decl(isArrayConformance2.ts, 37, 27)) +>a : Symbol(a, Decl(isArrayConformance2.ts, 37, 27)) +>a : Symbol(a, Decl(isArrayConformance2.ts, 37, 27)) +} + +function fg(arr1: T[], arr2: T[]) { +>fg : Symbol(fg, Decl(isArrayConformance2.ts, 39, 1)) +>T : Symbol(T, Decl(isArrayConformance2.ts, 41, 12)) +>arr1 : Symbol(arr1, Decl(isArrayConformance2.ts, 41, 27)) +>T : Symbol(T, Decl(isArrayConformance2.ts, 41, 12)) +>arr2 : Symbol(arr2, Decl(isArrayConformance2.ts, 41, 37)) +>T : Symbol(T, Decl(isArrayConformance2.ts, 41, 12)) + + for (let i = 0; i < arr1.length && i < arr2.length; i++) { +>i : Symbol(i, Decl(isArrayConformance2.ts, 42, 9)) +>i : Symbol(i, Decl(isArrayConformance2.ts, 42, 9)) +>arr1.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) +>arr1 : Symbol(arr1, Decl(isArrayConformance2.ts, 41, 27)) +>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) +>i : Symbol(i, Decl(isArrayConformance2.ts, 42, 9)) +>arr2.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) +>arr2 : Symbol(arr2, Decl(isArrayConformance2.ts, 41, 37)) +>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) +>i : Symbol(i, Decl(isArrayConformance2.ts, 42, 9)) + + const item1 = arr1[i]; +>item1 : Symbol(item1, Decl(isArrayConformance2.ts, 43, 7)) +>arr1 : Symbol(arr1, Decl(isArrayConformance2.ts, 41, 27)) +>i : Symbol(i, Decl(isArrayConformance2.ts, 42, 9)) + + const item2 = arr2[i]; +>item2 : Symbol(item2, Decl(isArrayConformance2.ts, 44, 7)) +>arr2 : Symbol(arr2, Decl(isArrayConformance2.ts, 41, 37)) +>i : Symbol(i, Decl(isArrayConformance2.ts, 42, 9)) + + if (Array.isArray(item1) && Array.isArray(item2)) { +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>item1 : Symbol(item1, Decl(isArrayConformance2.ts, 43, 7)) +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>item2 : Symbol(item2, Decl(isArrayConformance2.ts, 44, 7)) + + fg(item1, item2); // OK +>fg : Symbol(fg, Decl(isArrayConformance2.ts, 39, 1)) +>item1 : Symbol(item1, Decl(isArrayConformance2.ts, 43, 7)) +>item2 : Symbol(item2, Decl(isArrayConformance2.ts, 44, 7)) + } + } +} + +function fh(...args: [] | [attributes: ({ $: string } & Partial>) | Record, children?: any[]] | [children: any[]]) { +>fh : Symbol(fh, Decl(isArrayConformance2.ts, 49, 1)) +>args : Symbol(args, Decl(isArrayConformance2.ts, 51, 12)) +>$ : Symbol($, Decl(isArrayConformance2.ts, 51, 41)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) + + if (Array.isArray(args[0])) { +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>args : Symbol(args, Decl(isArrayConformance2.ts, 51, 12)) +>0 : Symbol(0) + + const children: (Record | HTMLElement)[] = args[0]; // OK +>children : Symbol(children, Decl(isArrayConformance2.ts, 53, 7)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) +>HTMLElement : Symbol(HTMLElement, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>HTMLElement : Symbol(HTMLElement, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>args : Symbol(args, Decl(isArrayConformance2.ts, 51, 12)) +>0 : Symbol(0) + } +} + diff --git a/tests/baselines/reference/isArrayConformance2.types b/tests/baselines/reference/isArrayConformance2.types index 72f9600444b56..e6e0d6a676306 100644 --- a/tests/baselines/reference/isArrayConformance2.types +++ b/tests/baselines/reference/isArrayConformance2.types @@ -6,9 +6,9 @@ function fa(a: [number, ...string[]] | readonly [boolean, boolean] | null) { if (Array.isArray(a)) { >Array.isArray(a) : boolean ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >a : [number, ...string[]] | readonly [boolean, boolean] a; // Expected: [number, ...string[]] | readonly [boolean, boolean] @@ -23,18 +23,18 @@ function fbArray.isArray(a) : boolean ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >a : T var b: [number, ...string[]] | readonly [boolean, boolean] = a; // OK >b : [number, ...string[]] | readonly [boolean, boolean] ->a : T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>a : T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never a[0]; // Expected: number | boolean >a[0] : number | boolean ->a : T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>a : T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >0 : 0 } } @@ -52,14 +52,14 @@ function fc(obj: T, prop: P) { if (Array.isArray(value)) { >Array.isArray(value) : boolean ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >value : T[P] value.length; // OK >value.length : number ->value : T[P] extends any ? Extract<(true extends false & T[P] ? any : T[P] extends string | readonly any[] ? unknown : T[P] extends ArrayLike ? U : unknown)[], T[P]> | Extract, T[P]> : never +>value : T[P] extends any ? (true extends false & T[P] ? Extract : T[P] extends string | readonly any[] ? never : T[P] extends ArrayLike ? Extract : never) | (true extends false & T[P] ? never : {} extends Required ? T[P] & any[] : Extract) : never >length : number } } @@ -70,14 +70,14 @@ function fd(value: Record) { if (Array.isArray(value)) { >Array.isArray(value) : boolean ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >value : Record value.length; // OK >value.length : number ->value : Record & unknown[] +>value : Record & any[] >length : number } } @@ -88,26 +88,26 @@ function fe(data: T) { if (Array.isArray(data)) { >Array.isArray(data) : boolean ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >data : T for (const key in data) { // OK ->key : Extract ? U : unknown)[], T> | Extract, T> : never), string> ->data : T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>key : Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never), string> +>data : T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never const value = data[key]; >value : any >data[key] : any ->data : T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never ->key : Extract ? U : unknown)[], T> | Extract, T> : never), string> +>data : T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never +>key : Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never), string> if (Array.isArray(value)) { >Array.isArray(value) : boolean ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >value : any value.length; // OK @@ -119,3 +119,97 @@ function fe(data: T) { } } +function ff(a: T | T[]): T[] { +>ff : (a: T | T[]) => T[] +>a : T | T[] + + return Array.isArray(a) ? a : [a]; // OK +>Array.isArray(a) ? a : [a] : T[] | (T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never) +>Array.isArray(a) : boolean +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never +>Array : ArrayConstructor +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never +>a : T | T[] +>a : T[] | (T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never) +>[a] : T[] +>a : T +} + +function fg(arr1: T[], arr2: T[]) { +>fg : (arr1: T[], arr2: T[]) => void +>arr1 : T[] +>arr2 : T[] + + for (let i = 0; i < arr1.length && i < arr2.length; i++) { +>i : number +>0 : 0 +>i < arr1.length && i < arr2.length : boolean +>i < arr1.length : boolean +>i : number +>arr1.length : number +>arr1 : T[] +>length : number +>i < arr2.length : boolean +>i : number +>arr2.length : number +>arr2 : T[] +>length : number +>i++ : number +>i : number + + const item1 = arr1[i]; +>item1 : T +>arr1[i] : T +>arr1 : T[] +>i : number + + const item2 = arr2[i]; +>item2 : T +>arr2[i] : T +>arr2 : T[] +>i : number + + if (Array.isArray(item1) && Array.isArray(item2)) { +>Array.isArray(item1) && Array.isArray(item2) : boolean +>Array.isArray(item1) : boolean +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never +>Array : ArrayConstructor +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never +>item1 : T +>Array.isArray(item2) : boolean +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never +>Array : ArrayConstructor +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never +>item2 : T + + fg(item1, item2); // OK +>fg(item1, item2) : void +>fg : (arr1: T[], arr2: T[]) => void +>item1 : T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never +>item2 : T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never + } + } +} + +function fh(...args: [] | [attributes: ({ $: string } & Partial>) | Record, children?: any[]] | [children: any[]]) { +>fh : (...args: [] | [attributes: ({ $: string;} & Partial>) | Record, children?: any[]] | [children: any[]]) => void +>args : [] | [attributes: Record | ({ $: string; } & Partial>), children?: any[]] | [children: any[]] +>$ : string + + if (Array.isArray(args[0])) { +>Array.isArray(args[0]) : boolean +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never +>Array : ArrayConstructor +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never +>args[0] : any[] | Record | ({ $: string; } & Partial>) +>args : [] | [attributes: Record | ({ $: string; } & Partial>), children?: any[]] | [children: any[]] +>0 : 0 + + const children: (Record | HTMLElement)[] = args[0]; // OK +>children : (HTMLElement | Record)[] +>args[0] : any[] | (Record & any[]) +>args : [] | [attributes: Record | ({ $: string; } & Partial>), children?: any[]] | [children: any[]] +>0 : 0 + } +} + diff --git a/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.errors.txt b/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.errors.txt index 60c04545c4273..fe028accbd6e2 100644 --- a/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.errors.txt +++ b/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.errors.txt @@ -1,6 +1,6 @@ -/src/a.js(10,7): error TS2417: Class static side 'typeof ElementsArray' incorrectly extends base class static side '{ isArray(arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; readonly prototype: any[]; }'. +/src/a.js(10,7): error TS2417: Class static side 'typeof ElementsArray' incorrectly extends base class static side '{ isArray(arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; readonly prototype: any[]; }'. Types of property 'isArray' are incompatible. - Type '(arg: any) => boolean' is not assignable to type '(arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never'. + Type '(arg: any) => boolean' is not assignable to type '(arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never'. Signature '(arg: any): boolean' must be a type predicate. @@ -16,9 +16,9 @@ // GH#46468 class ElementsArray extends Array { ~~~~~~~~~~~~~ -!!! error TS2417: Class static side 'typeof ElementsArray' incorrectly extends base class static side '{ isArray(arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; readonly prototype: any[]; }'. +!!! error TS2417: Class static side 'typeof ElementsArray' incorrectly extends base class static side '{ isArray(arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; readonly prototype: any[]; }'. !!! error TS2417: Types of property 'isArray' are incompatible. -!!! error TS2417: Type '(arg: any) => boolean' is not assignable to type '(arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never'. +!!! error TS2417: Type '(arg: any) => boolean' is not assignable to type '(arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never'. !!! error TS2417: Signature '(arg: any): boolean' must be a type predicate. static { const superisArray = super.isArray; diff --git a/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.types b/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.types index ef455079bf0c3..0aa4d36f18f2e 100644 --- a/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.types +++ b/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.types @@ -25,17 +25,17 @@ class ElementsArray extends Array { static { const superisArray = super.isArray; ->superisArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never ->super.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>superisArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never +>super.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >super : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never const customIsArray = (arg)=> superisArray(arg); >customIsArray : (arg: any) => boolean >(arg)=> superisArray(arg) : (arg: any) => boolean >arg : any >superisArray(arg) : boolean ->superisArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>superisArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >arg : any this.isArray = customIsArray; diff --git a/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.types b/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.types index 19c29b642ec73..be4032c30f240 100644 --- a/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.types +++ b/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.types @@ -66,9 +66,9 @@ function f2() { >a4 : (string | false) | (string | false)[] >Array.isArray(elOrA) ? elOrA : [elOrA] : (string | false)[] >Array.isArray(elOrA) : boolean ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >elOrA : (string | false) | (string | false)[] >elOrA : (string | false)[] >[elOrA] : (string | false)[] @@ -83,9 +83,9 @@ function f2() { >...Array.isArray(elOrA) ? elOrA : [elOrA] : string | false >Array.isArray(elOrA) ? elOrA : [elOrA] : (string | false)[] >Array.isArray(elOrA) : boolean ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >elOrA : (string | false) | (string | false)[] >elOrA : (string | false)[] >[elOrA] : (string | false)[] diff --git a/tests/baselines/reference/malformedTags.types b/tests/baselines/reference/malformedTags.types index be2e2f0be9315..a70d4053b1ad0 100644 --- a/tests/baselines/reference/malformedTags.types +++ b/tests/baselines/reference/malformedTags.types @@ -6,7 +6,7 @@ */ var isArray = Array.isArray; >isArray : Function ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never diff --git a/tests/baselines/reference/narrowingAssignmentReadonlyRespectsAssertion.types b/tests/baselines/reference/narrowingAssignmentReadonlyRespectsAssertion.types index 6018c86975c2f..8b3ca612352f2 100644 --- a/tests/baselines/reference/narrowingAssignmentReadonlyRespectsAssertion.types +++ b/tests/baselines/reference/narrowingAssignmentReadonlyRespectsAssertion.types @@ -100,9 +100,9 @@ function testFunc() { if (Array.isArray(val1)) { >Array.isArray(val1) : boolean ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >val1 : string | number | readonly (string | number)[] // This should retain val1 as being an array diff --git a/tests/baselines/reference/noIterationTypeErrorsInCFA.types b/tests/baselines/reference/noIterationTypeErrorsInCFA.types index 1bd904a5c25a0..4cd8a23be5ebe 100644 --- a/tests/baselines/reference/noIterationTypeErrorsInCFA.types +++ b/tests/baselines/reference/noIterationTypeErrorsInCFA.types @@ -10,9 +10,9 @@ export function doRemove(dds: F | F[]) { if (!Array.isArray(dds)) { >!Array.isArray(dds) : boolean >Array.isArray(dds) : boolean ->Array.isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>Array.isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >Array : ArrayConstructor ->isArray : { (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never; (arg: T): arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike | Iterable ? U : unknown)[], T> | Extract, T> : never; } +>isArray : { (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; (arg: T): arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike | Iterable ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never; } >dds : F | F[] dds = [dds] diff --git a/tests/baselines/reference/parserharness.types b/tests/baselines/reference/parserharness.types index a3bfcdbe751ab..070dd35e8740f 100644 --- a/tests/baselines/reference/parserharness.types +++ b/tests/baselines/reference/parserharness.types @@ -3068,13 +3068,13 @@ module Harness { >(Array.isArray && Array.isArray(arg)) || arg instanceof Array : boolean >(Array.isArray && Array.isArray(arg)) : boolean >Array.isArray && Array.isArray(arg) : boolean ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array.isArray(arg) : boolean ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >arg : any >arg instanceof Array : boolean >arg : any diff --git a/tests/baselines/reference/partiallyDiscriminantedUnions.types b/tests/baselines/reference/partiallyDiscriminantedUnions.types index 51aeba12844c0..0c65501f95dd7 100644 --- a/tests/baselines/reference/partiallyDiscriminantedUnions.types +++ b/tests/baselines/reference/partiallyDiscriminantedUnions.types @@ -77,9 +77,9 @@ function isShape(s : Shapes): s is Shape { return !Array.isArray(s); >!Array.isArray(s) : boolean >Array.isArray(s) : boolean ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >s : Shapes } diff --git a/tests/baselines/reference/spreadBooleanRespectsFreshness.types b/tests/baselines/reference/spreadBooleanRespectsFreshness.types index 271c9b91bc3d5..72819dcff94bc 100644 --- a/tests/baselines/reference/spreadBooleanRespectsFreshness.types +++ b/tests/baselines/reference/spreadBooleanRespectsFreshness.types @@ -22,9 +22,9 @@ foo1 = [...Array.isArray(foo2) ? foo2 : [foo2]]; >...Array.isArray(foo2) ? foo2 : [foo2] : FooBase >Array.isArray(foo2) ? foo2 : [foo2] : FooArray >Array.isArray(foo2) : boolean ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >foo2 : Foo >foo2 : FooArray >[foo2] : FooBase[] diff --git a/tests/baselines/reference/unknownControlFlow.types b/tests/baselines/reference/unknownControlFlow.types index 84b7ed332937a..9de498832688c 100644 --- a/tests/baselines/reference/unknownControlFlow.types +++ b/tests/baselines/reference/unknownControlFlow.types @@ -660,14 +660,14 @@ function deepEquals(a: T, b: T): boolean { if (Array.isArray(a) || Array.isArray(b)) { >Array.isArray(a) || Array.isArray(b) : boolean >Array.isArray(a) : boolean ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >a : T & object >Array.isArray(b) : boolean ->Array.isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>Array.isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >Array : ArrayConstructor ->isArray : (arg: T) => arg is T extends any ? Extract<(true extends false & T ? any : T extends string | readonly any[] ? unknown : T extends ArrayLike ? U : unknown)[], T> | Extract, T> : never +>isArray : (arg: T) => arg is T extends any ? (true extends false & T ? Extract : T extends string | readonly any[] ? never : T extends ArrayLike ? Extract : never) | (true extends false & T ? never : {} extends Required ? T & any[] : Extract) : never >b : T & object return false; diff --git a/tests/cases/compiler/isArrayConformance.ts b/tests/cases/compiler/isArrayConformance.ts index b1aa66a4ee6e2..b9a0c64d3d7b8 100644 --- a/tests/cases/compiler/isArrayConformance.ts +++ b/tests/cases/compiler/isArrayConformance.ts @@ -8,7 +8,7 @@ function f1(a: any) { function f2(a: unknown) { if (Array.isArray(a)) { - a; // Expected: unknown[] + a; // Expected: any[] } } @@ -40,7 +40,7 @@ function f6(a: (number[] | null | "loading")[]) { function f7(a: {} | null) { if (Array.isArray(a)) { - a; // Expected: unknown[] + a; // Expected: any[] } } diff --git a/tests/cases/compiler/isArrayConformance2.ts b/tests/cases/compiler/isArrayConformance2.ts index 459d9086c221f..40647d02bf9a2 100644 --- a/tests/cases/compiler/isArrayConformance2.ts +++ b/tests/cases/compiler/isArrayConformance2.ts @@ -34,3 +34,23 @@ function fe(data: T) { } } } + +function ff(a: T | T[]): T[] { + return Array.isArray(a) ? a : [a]; // OK +} + +function fg(arr1: T[], arr2: T[]) { + for (let i = 0; i < arr1.length && i < arr2.length; i++) { + const item1 = arr1[i]; + const item2 = arr2[i]; + if (Array.isArray(item1) && Array.isArray(item2)) { + fg(item1, item2); // OK + } + } +} + +function fh(...args: [] | [attributes: ({ $: string } & Partial>) | Record, children?: any[]] | [children: any[]]) { + if (Array.isArray(args[0])) { + const children: (Record | HTMLElement)[] = args[0]; // OK + } +}