From ce7e3c8cbb61be257e316d271222187ff5fffb3c Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Fri, 11 Mar 2022 10:32:12 -0700 Subject: [PATCH 1/2] isArray() preserve mutability and element type --- src/lib/es2015.iterable.d.ts | 2 ++ src/lib/es5.d.ts | 3 +- tests/cases/compiler/isArray.ts | 52 +++++++++++++++++++++++++++++---- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/lib/es2015.iterable.d.ts b/src/lib/es2015.iterable.d.ts index f1fb454f980b1..a3f5d15f501e9 100644 --- a/src/lib/es2015.iterable.d.ts +++ b/src/lib/es2015.iterable.d.ts @@ -56,6 +56,8 @@ interface Array { } interface ArrayConstructor { + isArray(arg: Iterable): arg is readonly T[]; + /** * Creates an array from an iterable object. * @param iterable An iterable object to convert to an array. diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index b0dc84de6b9f4..4ccf99839457c 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1443,7 +1443,8 @@ interface ArrayConstructor { (arrayLength?: number): any[]; (arrayLength: number): T[]; (...items: T[]): T[]; - isArray(arg: any): arg is any[]; + isArray(arg: ArrayLike): arg is readonly T[]; + isArray(arg: unknown): arg is any[]; readonly prototype: any[]; } diff --git a/tests/cases/compiler/isArray.ts b/tests/cases/compiler/isArray.ts index dbdd875e21ecc..b48b743367370 100644 --- a/tests/cases/compiler/isArray.ts +++ b/tests/cases/compiler/isArray.ts @@ -1,9 +1,49 @@ -var maybeArray: number | number[]; +// @target: es2015 +/// @errors: 2322 4104 +// https://github.com/microsoft/TypeScript/issues/17002 +// Preserves mutability, false branch removes arrays, mutable or not -if (Array.isArray(maybeArray)) { - maybeArray.length; // OK +declare const mutable: string | string[]; +if (Array.isArray(mutable)) { + const stillMutable: string[] = mutable; +} else { + const narrowed: string = mutable; +} + +declare const immutable: string | readonly string[]; +if (Array.isArray(immutable)) { + const notMutable: string[] = immutable; // Should fail: readonly string[] isn't assignable to string[] +} else { + const narrowed: string = immutable; +} + +// https://github.com/microsoft/TypeScript/issues/33700 +// Preserves element or iterated type of wider types + +declare const arrayLike: string | ArrayLike; +if (Array.isArray(arrayLike)) { + const arrayOfElementType: readonly string[] = arrayLike; + const notArrayOfAny: readonly void[] = arrayLike; // Should fail: string isn't assignable to void +} + +declare const iterable: string | Iterable; +if (Array.isArray(iterable)) { + const arrayOfIteratedType: readonly string[] = iterable; + const notArrayOfAny: readonly void[] = iterable; // Should fail: string isn't assignable to void +} + +// https://github.com/microsoft/TypeScript/pull/42316#discussion_r823218462 +// any and unknown backward compatibility + +declare const any: any; +if (Array.isArray(any)) { + const mutableArrayOfAny: void[] = any; + const notAny: void = any; // Should fail: any[] isn't assignable to void +} + +declare const unknown: unknown; +if (Array.isArray(unknown)) { + const mutableArrayOfAny: void[] = unknown; + const notAny: void = unknown; // Should fail: any[] isn't assignable to void } -else { - maybeArray.toFixed(); // OK -} \ No newline at end of file From 8f908812977f5d0e4b910f8ec7cbcb216c0f7693 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Fri, 11 Mar 2022 21:43:52 +0000 Subject: [PATCH 2/2] Update Baselines and/or Applied Lint Fixes --- .../arrayDestructuringInSwitch1.symbols | 4 +- .../arrayDestructuringInSwitch1.types | 4 +- .../reference/arrayTypeOfTypeOf.types | 4 +- ...ternalTypesProduceUniqueTypeParams.symbols | 4 +- ...InternalTypesProduceUniqueTypeParams.types | 4 +- ...tructuringParameterDeclaration4.errors.txt | 2 +- .../reference/fixSignatureCaching.symbols | 8 +- .../reference/fixSignatureCaching.types | 8 +- .../reference/instantiationExpressions.types | 8 +- tests/baselines/reference/isArray.errors.txt | 69 +++++++++ tests/baselines/reference/isArray.js | 82 +++++++++-- tests/baselines/reference/isArray.symbols | 134 +++++++++++++++-- tests/baselines/reference/isArray.types | 138 +++++++++++++++--- ...riptThisAssignmentInStaticBlock.errors.txt | 8 +- ...ascriptThisAssignmentInStaticBlock.symbols | 4 +- ...avascriptThisAssignmentInStaticBlock.types | 8 +- ...ralFreshnessPropagationOnNarrowing.symbols | 8 +- ...teralFreshnessPropagationOnNarrowing.types | 8 +- .../baselines/reference/malformedTags.symbols | 4 +- tests/baselines/reference/malformedTags.types | 4 +- ...ssignmentReadonlyRespectsAssertion.symbols | 4 +- ...gAssignmentReadonlyRespectsAssertion.types | 4 +- .../noIterationTypeErrorsInCFA.symbols | 4 +- .../noIterationTypeErrorsInCFA.types | 4 +- .../baselines/reference/parserharness.symbols | 8 +- tests/baselines/reference/parserharness.types | 8 +- .../partiallyDiscriminantedUnions.symbols | 4 +- .../partiallyDiscriminantedUnions.types | 4 +- .../reference/promisePermutations.errors.txt | 2 +- .../reference/promisePermutations2.errors.txt | 2 +- .../reference/promisePermutations3.errors.txt | 4 +- .../spreadBooleanRespectsFreshness.symbols | 4 +- .../spreadBooleanRespectsFreshness.types | 4 +- 33 files changed, 453 insertions(+), 116 deletions(-) create mode 100644 tests/baselines/reference/isArray.errors.txt diff --git a/tests/baselines/reference/arrayDestructuringInSwitch1.symbols b/tests/baselines/reference/arrayDestructuringInSwitch1.symbols index f1a9bea3fa35f..47eced478abf2 100644 --- a/tests/baselines/reference/arrayDestructuringInSwitch1.symbols +++ b/tests/baselines/reference/arrayDestructuringInSwitch1.symbols @@ -14,9 +14,9 @@ export function evaluate(expression: Expression): boolean { >Expression : Symbol(Expression, Decl(arrayDestructuringInSwitch1.ts, 0, 0)) if (Array.isArray(expression)) { ->Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), 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, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >expression : Symbol(expression, Decl(arrayDestructuringInSwitch1.ts, 3, 25)) const [operator, ...operands] = expression; diff --git a/tests/baselines/reference/arrayDestructuringInSwitch1.types b/tests/baselines/reference/arrayDestructuringInSwitch1.types index dfb06774cec16..707a7cc3d3ccb 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: any) => arg is any[] +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >Array : ArrayConstructor ->isArray : (arg: any) => arg is any[] +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >expression : Expression const [operator, ...operands] = expression; diff --git a/tests/baselines/reference/arrayTypeOfTypeOf.types b/tests/baselines/reference/arrayTypeOfTypeOf.types index 60eec5fbba21b..79fed5b069b39 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: any): arg is any[]; readonly prototype: any[]; } +>xs3 : { (arrayLength: number): number[]; (...items: number[]): number[]; new (arrayLength: number): number[]; new (...items: number[]): number[]; isArray(arg: ArrayLike): arg is readonly T[]; isArray(arg: unknown): arg is any[]; 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: any): arg is any[]; readonly prototype: any[]; } +>xs4 : { (arrayLength: number): number[]; (...items: number[]): number[]; new (arrayLength: number): number[]; new (...items: number[]): number[]; isArray(arg: ArrayLike): arg is readonly T[]; isArray(arg: unknown): arg is any[]; readonly prototype: any[]; } >Array : ArrayConstructor >x : number diff --git a/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.symbols b/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.symbols index 08c4eccca0829..dab40f82aa383 100644 --- a/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.symbols +++ b/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.symbols @@ -79,9 +79,9 @@ export const updateIfChanged = (t: T) => { >Object.assign : Symbol(ObjectConstructor.assign, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) >Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >assign : Symbol(ObjectConstructor.assign, Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --)) ->Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) ->isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) >u : Symbol(u, Decl(declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.ts, 7, 23)) >u : Symbol(u, Decl(declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.ts, 7, 23)) >[key] : Symbol([key], Decl(declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.ts, 12, 80)) diff --git a/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types b/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types index 4e4bf5b76933a..ed6f7a91f25a7 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: any) => arg is any[] +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T[]; } >Array : ArrayConstructor ->isArray : (arg: any) => arg is any[] +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T[]; } >u : U >[] : undefined[] >{} : {} diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt index 4f9b905252e09..fd1fa5ba94dfe 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt @@ -41,7 +41,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts( a1(...array2); // Error parameter type is (number|string)[] ~~~~~~ !!! error TS2552: Cannot find name 'array2'. Did you mean 'Array'? -!!! related TS2728 /.ts/lib.es5.d.ts:1470:13: 'Array' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1471:13: 'Array' is declared here. a5([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] ~~~~~~~~ !!! error TS2322: Type 'string' is not assignable to type '[[any]]'. diff --git a/tests/baselines/reference/fixSignatureCaching.symbols b/tests/baselines/reference/fixSignatureCaching.symbols index 0ec1d2c63aae8..e221b2a3eb042 100644 --- a/tests/baselines/reference/fixSignatureCaching.symbols +++ b/tests/baselines/reference/fixSignatureCaching.symbols @@ -796,9 +796,9 @@ define(function () { >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) Array.isArray : function (value) { return Object.prototype.toString.call(value) === '[object Array]'; }; ->Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), 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, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >value : Symbol(value, Decl(fixSignatureCaching.ts, 297, 34)) >Object.prototype.toString.call : Symbol(Function.call, Decl(lib.es5.d.ts, --, --)) >Object.prototype.toString : Symbol(Object.toString, Decl(lib.es5.d.ts, --, --)) @@ -825,9 +825,9 @@ define(function () { >value : Symbol(value, Decl(fixSignatureCaching.ts, 299, 20)) : Array.isArray; ->Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), 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, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) function equalIC(a, b) { >equalIC : Symbol(equalIC, Decl(fixSignatureCaching.ts, 300, 24)) diff --git a/tests/baselines/reference/fixSignatureCaching.types b/tests/baselines/reference/fixSignatureCaching.types index 06ab4f3df7eee..cdf8b8b83ad2e 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: any) => arg is any[] +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >Array : ArrayConstructor ->isArray : (arg: any) => arg is any[] +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >function (value) { return Object.prototype.toString.call(value) === '[object Array]'; } : (value: any) => boolean >value : any >Object.prototype.toString.call(value) === '[object Array]' : boolean @@ -1150,9 +1150,9 @@ define(function () { >'[object Array]' : "[object Array]" : Array.isArray; ->Array.isArray : (arg: any) => arg is any[] +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >Array : ArrayConstructor ->isArray : (arg: any) => arg is any[] +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } function equalIC(a, b) { >equalIC : (a: any, b: any) => boolean diff --git a/tests/baselines/reference/instantiationExpressions.types b/tests/baselines/reference/instantiationExpressions.types index 43a71f42d3ea5..bca96ca955b33 100644 --- a/tests/baselines/reference/instantiationExpressions.types +++ b/tests/baselines/reference/instantiationExpressions.types @@ -56,11 +56,11 @@ 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: any): arg is any[]; readonly prototype: any[]; } +>A1 : { (arrayLength: number): string[]; (...items: string[]): string[]; new (arrayLength: number): string[]; new (...items: string[]): string[]; isArray(arg: ArrayLike): arg is readonly T[]; isArray(arg: unknown): arg is any[]; readonly prototype: any[]; } >Array : ArrayConstructor const A2 = Array; // Error ->A2 : { isArray(arg: any): arg is any[]; readonly prototype: any[]; } +>A2 : { isArray(arg: ArrayLike): arg is readonly T[]; isArray(arg: unknown): arg is any[]; readonly prototype: any[]; } >Array : ArrayConstructor } @@ -69,11 +69,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: any): arg is any[]; readonly prototype: any[]; } +>T21 : { (arrayLength: number): string[]; (...items: string[]): string[]; new (arrayLength: number): string[]; new (...items: string[]): string[]; isArray(arg: ArrayLike): arg is readonly T[]; isArray(arg: unknown): arg is any[]; readonly prototype: any[]; } >Array : ArrayConstructor type T22 = typeof Array; // Error ->T22 : { isArray(arg: any): arg is any[]; readonly prototype: any[]; } +>T22 : { isArray(arg: ArrayLike): arg is readonly T[]; isArray(arg: unknown): arg is any[]; readonly prototype: any[]; } >Array : ArrayConstructor declare class C { diff --git a/tests/baselines/reference/isArray.errors.txt b/tests/baselines/reference/isArray.errors.txt new file mode 100644 index 0000000000000..742a8a64a65bc --- /dev/null +++ b/tests/baselines/reference/isArray.errors.txt @@ -0,0 +1,69 @@ +tests/cases/compiler/isArray.ts(15,9): error TS4104: The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type 'string[]'. +tests/cases/compiler/isArray.ts(26,9): error TS2322: Type 'readonly string[]' is not assignable to type 'readonly void[]'. + Type 'string' is not assignable to type 'void'. +tests/cases/compiler/isArray.ts(32,9): error TS2322: Type 'readonly string[]' is not assignable to type 'readonly void[]'. +tests/cases/compiler/isArray.ts(41,9): error TS2322: Type 'any[]' is not assignable to type 'void'. +tests/cases/compiler/isArray.ts(47,9): error TS2322: Type 'any[]' is not assignable to type 'void'. + + +==== tests/cases/compiler/isArray.ts (5 errors) ==== + /// @errors: 2322 4104 + + // https://github.com/microsoft/TypeScript/issues/17002 + // Preserves mutability, false branch removes arrays, mutable or not + + declare const mutable: string | string[]; + if (Array.isArray(mutable)) { + const stillMutable: string[] = mutable; + } else { + const narrowed: string = mutable; + } + + declare const immutable: string | readonly string[]; + if (Array.isArray(immutable)) { + const notMutable: string[] = immutable; // Should fail: readonly string[] isn't assignable to string[] + ~~~~~~~~~~ +!!! error TS4104: The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type 'string[]'. + } else { + const narrowed: string = immutable; + } + + // https://github.com/microsoft/TypeScript/issues/33700 + // Preserves element or iterated type of wider types + + declare const arrayLike: string | ArrayLike; + if (Array.isArray(arrayLike)) { + const arrayOfElementType: readonly string[] = arrayLike; + const notArrayOfAny: readonly void[] = arrayLike; // Should fail: string isn't assignable to void + ~~~~~~~~~~~~~ +!!! error TS2322: Type 'readonly string[]' is not assignable to type 'readonly void[]'. +!!! error TS2322: Type 'string' is not assignable to type 'void'. + } + + declare const iterable: string | Iterable; + if (Array.isArray(iterable)) { + const arrayOfIteratedType: readonly string[] = iterable; + const notArrayOfAny: readonly void[] = iterable; // Should fail: string isn't assignable to void + ~~~~~~~~~~~~~ +!!! error TS2322: Type 'readonly string[]' is not assignable to type 'readonly void[]'. + } + + // https://github.com/microsoft/TypeScript/pull/42316#discussion_r823218462 + // any and unknown backward compatibility + + declare const any: any; + if (Array.isArray(any)) { + const mutableArrayOfAny: void[] = any; + const notAny: void = any; // Should fail: any[] isn't assignable to void + ~~~~~~ +!!! error TS2322: Type 'any[]' is not assignable to type 'void'. + } + + declare const unknown: unknown; + if (Array.isArray(unknown)) { + const mutableArrayOfAny: void[] = unknown; + const notAny: void = unknown; // Should fail: any[] isn't assignable to void + ~~~~~~ +!!! error TS2322: Type 'any[]' is not assignable to type 'void'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/isArray.js b/tests/baselines/reference/isArray.js index a90898fd65b26..53b5eabeb74a4 100644 --- a/tests/baselines/reference/isArray.js +++ b/tests/baselines/reference/isArray.js @@ -1,19 +1,81 @@ //// [isArray.ts] -var maybeArray: number | number[]; +/// @errors: 2322 4104 +// https://github.com/microsoft/TypeScript/issues/17002 +// Preserves mutability, false branch removes arrays, mutable or not -if (Array.isArray(maybeArray)) { - maybeArray.length; // OK +declare const mutable: string | string[]; +if (Array.isArray(mutable)) { + const stillMutable: string[] = mutable; +} else { + const narrowed: string = mutable; } -else { - maybeArray.toFixed(); // OK -} + +declare const immutable: string | readonly string[]; +if (Array.isArray(immutable)) { + const notMutable: string[] = immutable; // Should fail: readonly string[] isn't assignable to string[] +} else { + const narrowed: string = immutable; +} + +// https://github.com/microsoft/TypeScript/issues/33700 +// Preserves element or iterated type of wider types + +declare const arrayLike: string | ArrayLike; +if (Array.isArray(arrayLike)) { + const arrayOfElementType: readonly string[] = arrayLike; + const notArrayOfAny: readonly void[] = arrayLike; // Should fail: string isn't assignable to void +} + +declare const iterable: string | Iterable; +if (Array.isArray(iterable)) { + const arrayOfIteratedType: readonly string[] = iterable; + const notArrayOfAny: readonly void[] = iterable; // Should fail: string isn't assignable to void +} + +// https://github.com/microsoft/TypeScript/pull/42316#discussion_r823218462 +// any and unknown backward compatibility + +declare const any: any; +if (Array.isArray(any)) { + const mutableArrayOfAny: void[] = any; + const notAny: void = any; // Should fail: any[] isn't assignable to void +} + +declare const unknown: unknown; +if (Array.isArray(unknown)) { + const mutableArrayOfAny: void[] = unknown; + const notAny: void = unknown; // Should fail: any[] isn't assignable to void +} + //// [isArray.js] -var maybeArray; -if (Array.isArray(maybeArray)) { - maybeArray.length; // OK +/// @errors: 2322 4104 +if (Array.isArray(mutable)) { + const stillMutable = mutable; +} +else { + const narrowed = mutable; +} +if (Array.isArray(immutable)) { + const notMutable = immutable; // Should fail: readonly string[] isn't assignable to string[] } else { - maybeArray.toFixed(); // OK + const narrowed = immutable; +} +if (Array.isArray(arrayLike)) { + const arrayOfElementType = arrayLike; + const notArrayOfAny = arrayLike; // Should fail: string isn't assignable to void +} +if (Array.isArray(iterable)) { + const arrayOfIteratedType = iterable; + const notArrayOfAny = iterable; // Should fail: string isn't assignable to void +} +if (Array.isArray(any)) { + const mutableArrayOfAny = any; + const notAny = any; // Should fail: any[] isn't assignable to void +} +if (Array.isArray(unknown)) { + const mutableArrayOfAny = unknown; + const notAny = unknown; // Should fail: any[] isn't assignable to void } diff --git a/tests/baselines/reference/isArray.symbols b/tests/baselines/reference/isArray.symbols index 411cb42918daa..1306818014903 100644 --- a/tests/baselines/reference/isArray.symbols +++ b/tests/baselines/reference/isArray.symbols @@ -1,22 +1,124 @@ === tests/cases/compiler/isArray.ts === -var maybeArray: number | number[]; ->maybeArray : Symbol(maybeArray, Decl(isArray.ts, 0, 3)) +/// @errors: 2322 4104 +// https://github.com/microsoft/TypeScript/issues/17002 +// Preserves mutability, false branch removes arrays, mutable or not -if (Array.isArray(maybeArray)) { ->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, --, --)) ->maybeArray : Symbol(maybeArray, Decl(isArray.ts, 0, 3)) +declare const mutable: string | string[]; +>mutable : Symbol(mutable, Decl(isArray.ts, 5, 13)) - maybeArray.length; // OK ->maybeArray.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) ->maybeArray : Symbol(maybeArray, Decl(isArray.ts, 0, 3)) ->length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) +if (Array.isArray(mutable)) { +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>mutable : Symbol(mutable, Decl(isArray.ts, 5, 13)) + + const stillMutable: string[] = mutable; +>stillMutable : Symbol(stillMutable, Decl(isArray.ts, 7, 7)) +>mutable : Symbol(mutable, Decl(isArray.ts, 5, 13)) + +} else { + const narrowed: string = mutable; +>narrowed : Symbol(narrowed, Decl(isArray.ts, 9, 7)) +>mutable : Symbol(mutable, Decl(isArray.ts, 5, 13)) } -else { - maybeArray.toFixed(); // OK ->maybeArray.toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --)) ->maybeArray : Symbol(maybeArray, Decl(isArray.ts, 0, 3)) ->toFixed : Symbol(Number.toFixed, Decl(lib.es5.d.ts, --, --)) + +declare const immutable: string | readonly string[]; +>immutable : Symbol(immutable, Decl(isArray.ts, 12, 13)) + +if (Array.isArray(immutable)) { +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>immutable : Symbol(immutable, Decl(isArray.ts, 12, 13)) + + const notMutable: string[] = immutable; // Should fail: readonly string[] isn't assignable to string[] +>notMutable : Symbol(notMutable, Decl(isArray.ts, 14, 7)) +>immutable : Symbol(immutable, Decl(isArray.ts, 12, 13)) + +} else { + const narrowed: string = immutable; +>narrowed : Symbol(narrowed, Decl(isArray.ts, 16, 7)) +>immutable : Symbol(immutable, Decl(isArray.ts, 12, 13)) } + +// https://github.com/microsoft/TypeScript/issues/33700 +// Preserves element or iterated type of wider types + +declare const arrayLike: string | ArrayLike; +>arrayLike : Symbol(arrayLike, Decl(isArray.ts, 22, 13)) +>ArrayLike : Symbol(ArrayLike, Decl(lib.es5.d.ts, --, --)) + +if (Array.isArray(arrayLike)) { +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>arrayLike : Symbol(arrayLike, Decl(isArray.ts, 22, 13)) + + const arrayOfElementType: readonly string[] = arrayLike; +>arrayOfElementType : Symbol(arrayOfElementType, Decl(isArray.ts, 24, 7)) +>arrayLike : Symbol(arrayLike, Decl(isArray.ts, 22, 13)) + + const notArrayOfAny: readonly void[] = arrayLike; // Should fail: string isn't assignable to void +>notArrayOfAny : Symbol(notArrayOfAny, Decl(isArray.ts, 25, 7)) +>arrayLike : Symbol(arrayLike, Decl(isArray.ts, 22, 13)) +} + +declare const iterable: string | Iterable; +>iterable : Symbol(iterable, Decl(isArray.ts, 28, 13)) +>Iterable : Symbol(Iterable, Decl(lib.es2015.iterable.d.ts, --, --)) + +if (Array.isArray(iterable)) { +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>iterable : Symbol(iterable, Decl(isArray.ts, 28, 13)) + + const arrayOfIteratedType: readonly string[] = iterable; +>arrayOfIteratedType : Symbol(arrayOfIteratedType, Decl(isArray.ts, 30, 7)) +>iterable : Symbol(iterable, Decl(isArray.ts, 28, 13)) + + const notArrayOfAny: readonly void[] = iterable; // Should fail: string isn't assignable to void +>notArrayOfAny : Symbol(notArrayOfAny, Decl(isArray.ts, 31, 7)) +>iterable : Symbol(iterable, Decl(isArray.ts, 28, 13)) +} + +// https://github.com/microsoft/TypeScript/pull/42316#discussion_r823218462 +// any and unknown backward compatibility + +declare const any: any; +>any : Symbol(any, Decl(isArray.ts, 37, 13)) + +if (Array.isArray(any)) { +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>any : Symbol(any, Decl(isArray.ts, 37, 13)) + + const mutableArrayOfAny: void[] = any; +>mutableArrayOfAny : Symbol(mutableArrayOfAny, Decl(isArray.ts, 39, 7)) +>any : Symbol(any, Decl(isArray.ts, 37, 13)) + + const notAny: void = any; // Should fail: any[] isn't assignable to void +>notAny : Symbol(notAny, Decl(isArray.ts, 40, 7)) +>any : Symbol(any, Decl(isArray.ts, 37, 13)) +} + +declare const unknown: unknown; +>unknown : Symbol(unknown, Decl(isArray.ts, 43, 13)) + +if (Array.isArray(unknown)) { +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>unknown : Symbol(unknown, Decl(isArray.ts, 43, 13)) + + const mutableArrayOfAny: void[] = unknown; +>mutableArrayOfAny : Symbol(mutableArrayOfAny, Decl(isArray.ts, 45, 7)) +>unknown : Symbol(unknown, Decl(isArray.ts, 43, 13)) + + const notAny: void = unknown; // Should fail: any[] isn't assignable to void +>notAny : Symbol(notAny, Decl(isArray.ts, 46, 7)) +>unknown : Symbol(unknown, Decl(isArray.ts, 43, 13)) +} + diff --git a/tests/baselines/reference/isArray.types b/tests/baselines/reference/isArray.types index bc452b12bef01..bf5dc8a102422 100644 --- a/tests/baselines/reference/isArray.types +++ b/tests/baselines/reference/isArray.types @@ -1,24 +1,128 @@ === tests/cases/compiler/isArray.ts === -var maybeArray: number | number[]; ->maybeArray : number | number[] +/// @errors: 2322 4104 +// https://github.com/microsoft/TypeScript/issues/17002 +// Preserves mutability, false branch removes arrays, mutable or not -if (Array.isArray(maybeArray)) { ->Array.isArray(maybeArray) : boolean ->Array.isArray : (arg: any) => arg is any[] +declare const mutable: string | string[]; +>mutable : string | string[] + +if (Array.isArray(mutable)) { +>Array.isArray(mutable) : boolean +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T[]; } +>Array : ArrayConstructor +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T[]; } +>mutable : string | string[] + + const stillMutable: string[] = mutable; +>stillMutable : string[] +>mutable : string[] + +} else { + const narrowed: string = mutable; +>narrowed : string +>mutable : string +} + +declare const immutable: string | readonly string[]; +>immutable : string | readonly string[] + +if (Array.isArray(immutable)) { +>Array.isArray(immutable) : boolean +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T[]; } +>Array : ArrayConstructor +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T[]; } +>immutable : string | readonly string[] + + const notMutable: string[] = immutable; // Should fail: readonly string[] isn't assignable to string[] +>notMutable : string[] +>immutable : readonly string[] + +} else { + const narrowed: string = immutable; +>narrowed : string +>immutable : string +} + +// https://github.com/microsoft/TypeScript/issues/33700 +// Preserves element or iterated type of wider types + +declare const arrayLike: string | ArrayLike; +>arrayLike : string | ArrayLike + +if (Array.isArray(arrayLike)) { +>Array.isArray(arrayLike) : boolean +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T[]; } +>Array : ArrayConstructor +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T[]; } +>arrayLike : string | ArrayLike + + const arrayOfElementType: readonly string[] = arrayLike; +>arrayOfElementType : readonly string[] +>arrayLike : readonly string[] + + const notArrayOfAny: readonly void[] = arrayLike; // Should fail: string isn't assignable to void +>notArrayOfAny : readonly void[] +>arrayLike : readonly string[] +} + +declare const iterable: string | Iterable; +>iterable : string | Iterable + +if (Array.isArray(iterable)) { +>Array.isArray(iterable) : boolean +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T[]; } >Array : ArrayConstructor ->isArray : (arg: any) => arg is any[] ->maybeArray : number | number[] +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T[]; } +>iterable : string | Iterable - maybeArray.length; // OK ->maybeArray.length : number ->maybeArray : number[] ->length : number + const arrayOfIteratedType: readonly string[] = iterable; +>arrayOfIteratedType : readonly string[] +>iterable : readonly string[] + + const notArrayOfAny: readonly void[] = iterable; // Should fail: string isn't assignable to void +>notArrayOfAny : readonly void[] +>iterable : readonly string[] } -else { - maybeArray.toFixed(); // OK ->maybeArray.toFixed() : string ->maybeArray.toFixed : (fractionDigits?: number) => string ->maybeArray : number ->toFixed : (fractionDigits?: number) => string + +// https://github.com/microsoft/TypeScript/pull/42316#discussion_r823218462 +// any and unknown backward compatibility + +declare const any: any; +>any : any + +if (Array.isArray(any)) { +>Array.isArray(any) : boolean +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T[]; } +>Array : ArrayConstructor +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T[]; } +>any : any + + const mutableArrayOfAny: void[] = any; +>mutableArrayOfAny : void[] +>any : any[] + + const notAny: void = any; // Should fail: any[] isn't assignable to void +>notAny : void +>any : any[] +} + +declare const unknown: unknown; +>unknown : unknown + +if (Array.isArray(unknown)) { +>Array.isArray(unknown) : boolean +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T[]; } +>Array : ArrayConstructor +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T[]; } +>unknown : unknown + + const mutableArrayOfAny: void[] = unknown; +>mutableArrayOfAny : void[] +>unknown : any[] + + const notAny: void = unknown; // Should fail: any[] isn't assignable to void +>notAny : void +>unknown : any[] } + diff --git a/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.errors.txt b/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.errors.txt index a4729d56ef55b..1517fbfc8277a 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: any): arg is any[]; readonly prototype: any[]; }'. +/src/a.js(10,7): error TS2417: Class static side 'typeof ElementsArray' incorrectly extends base class static side '{ isArray(arg: ArrayLike): arg is readonly T[]; isArray(arg: unknown): arg is any[]; readonly prototype: any[]; }'. Types of property 'isArray' are incompatible. - Type '(arg: any) => boolean' is not assignable to type '(arg: any) => arg is any[]'. + Type '(arg: any) => boolean' is not assignable to type '{ (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; }'. 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: any): arg is any[]; readonly prototype: any[]; }'. +!!! error TS2417: Class static side 'typeof ElementsArray' incorrectly extends base class static side '{ isArray(arg: ArrayLike): arg is readonly T[]; isArray(arg: unknown): arg is any[]; readonly prototype: any[]; }'. !!! error TS2417: Types of property 'isArray' are incompatible. -!!! error TS2417: Type '(arg: any) => boolean' is not assignable to type '(arg: any) => arg is any[]'. +!!! error TS2417: Type '(arg: any) => boolean' is not assignable to type '{ (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; }'. !!! error TS2417: Signature '(arg: any): boolean' must be a type predicate. static { const superisArray = super.isArray; diff --git a/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.symbols b/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.symbols index 51d648a9ed77c..adbc87357cc9a 100644 --- a/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.symbols +++ b/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.symbols @@ -23,9 +23,9 @@ class ElementsArray extends Array { static { const superisArray = super.isArray; >superisArray : Symbol(superisArray, Decl(a.js, 11, 13)) ->super.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>super.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >super : Symbol(ArrayConstructor, Decl(lib.es5.d.ts, --, --)) ->isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) const customIsArray = (arg)=> superisArray(arg); >customIsArray : Symbol(customIsArray, Decl(a.js, 12, 13)) diff --git a/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.types b/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.types index bbb41f4ea47fd..bb11320009c57 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: any) => arg is any[] ->super.isArray : (arg: any) => arg is any[] +>superisArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } +>super.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >super : ArrayConstructor ->isArray : (arg: any) => arg is any[] +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } const customIsArray = (arg)=> superisArray(arg); >customIsArray : (arg: any) => boolean >(arg)=> superisArray(arg) : (arg: any) => boolean >arg : any >superisArray(arg) : boolean ->superisArray : (arg: any) => arg is any[] +>superisArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >arg : any this.isArray = customIsArray; diff --git a/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.symbols b/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.symbols index 790def0be4318..7d783ed26771a 100644 --- a/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.symbols +++ b/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.symbols @@ -61,9 +61,9 @@ function f2() { let a4: ElementOrArray = Array.isArray(elOrA) ? elOrA : [elOrA]; >a4 : Symbol(a4, Decl(literalFreshnessPropagationOnNarrowing.ts, 21, 7)) >ElementOrArray : Symbol(ElementOrArray, Decl(literalFreshnessPropagationOnNarrowing.ts, 11, 36)) ->Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), 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, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >elOrA : Symbol(elOrA, Decl(literalFreshnessPropagationOnNarrowing.ts, 15, 7)) >elOrA : Symbol(elOrA, Decl(literalFreshnessPropagationOnNarrowing.ts, 15, 7)) >elOrA : Symbol(elOrA, Decl(literalFreshnessPropagationOnNarrowing.ts, 15, 7)) @@ -74,9 +74,9 @@ function f2() { let a5: ElementOrArray = [...Array.isArray(elOrA) ? elOrA : [elOrA]]; >a5 : Symbol(a5, Decl(literalFreshnessPropagationOnNarrowing.ts, 26, 7)) >ElementOrArray : Symbol(ElementOrArray, Decl(literalFreshnessPropagationOnNarrowing.ts, 11, 36)) ->Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), 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, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >elOrA : Symbol(elOrA, Decl(literalFreshnessPropagationOnNarrowing.ts, 15, 7)) >elOrA : Symbol(elOrA, Decl(literalFreshnessPropagationOnNarrowing.ts, 15, 7)) >elOrA : Symbol(elOrA, Decl(literalFreshnessPropagationOnNarrowing.ts, 15, 7)) diff --git a/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.types b/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.types index fd3858baebc68..e5fb88a30c314 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: any) => arg is any[] +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >Array : ArrayConstructor ->isArray : (arg: any) => arg is any[] +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >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: any) => arg is any[] +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >Array : ArrayConstructor ->isArray : (arg: any) => arg is any[] +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >elOrA : (string | false) | (string | false)[] >elOrA : (string | false)[] >[elOrA] : (string | false)[] diff --git a/tests/baselines/reference/malformedTags.symbols b/tests/baselines/reference/malformedTags.symbols index bd0dc3d4a80f8..4d8b6db454e2e 100644 --- a/tests/baselines/reference/malformedTags.symbols +++ b/tests/baselines/reference/malformedTags.symbols @@ -6,7 +6,7 @@ */ var isArray = Array.isArray; >isArray : Symbol(isArray, Decl(myFile02.js, 5, 3)) ->Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), 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, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) diff --git a/tests/baselines/reference/malformedTags.types b/tests/baselines/reference/malformedTags.types index c3af959586790..a2f34834f9477 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: any) => arg is any[] +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >Array : ArrayConstructor ->isArray : (arg: any) => arg is any[] +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } diff --git a/tests/baselines/reference/narrowingAssignmentReadonlyRespectsAssertion.symbols b/tests/baselines/reference/narrowingAssignmentReadonlyRespectsAssertion.symbols index 8b7fcfebae44f..b7aff0f177d1d 100644 --- a/tests/baselines/reference/narrowingAssignmentReadonlyRespectsAssertion.symbols +++ b/tests/baselines/reference/narrowingAssignmentReadonlyRespectsAssertion.symbols @@ -82,9 +82,9 @@ function testFunc() { >val2 : Symbol(val2, Decl(narrowingAssignmentReadonlyRespectsAssertion.ts, 26, 32)) if (Array.isArray(val1)) { ->Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), 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, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >val1 : Symbol(val1, Decl(narrowingAssignmentReadonlyRespectsAssertion.ts, 26, 26)) // This should retain val1 as being an array diff --git a/tests/baselines/reference/narrowingAssignmentReadonlyRespectsAssertion.types b/tests/baselines/reference/narrowingAssignmentReadonlyRespectsAssertion.types index 9fd13d661027a..f0ba9aaa4633f 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: any) => arg is any[] +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >Array : ArrayConstructor ->isArray : (arg: any) => arg is any[] +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >val1 : string | number | readonly (string | number)[] // This should retain val1 as being an array diff --git a/tests/baselines/reference/noIterationTypeErrorsInCFA.symbols b/tests/baselines/reference/noIterationTypeErrorsInCFA.symbols index 60040c3ed17c4..5c1b9083f2249 100644 --- a/tests/baselines/reference/noIterationTypeErrorsInCFA.symbols +++ b/tests/baselines/reference/noIterationTypeErrorsInCFA.symbols @@ -12,9 +12,9 @@ export function doRemove(dds: F | F[]) { >F : Symbol(F, Decl(noIterationTypeErrorsInCFA.ts, 0, 0)) if (!Array.isArray(dds)) { ->Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --) ... and 3 more) ->isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) >dds : Symbol(dds, Decl(noIterationTypeErrorsInCFA.ts, 3, 25)) dds = [dds] diff --git a/tests/baselines/reference/noIterationTypeErrorsInCFA.types b/tests/baselines/reference/noIterationTypeErrorsInCFA.types index 9d0122627ffae..ec2a13d77261f 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: any) => arg is any[] +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T[]; } >Array : ArrayConstructor ->isArray : (arg: any) => arg is any[] +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T[]; } >dds : F | F[] dds = [dds] diff --git a/tests/baselines/reference/parserharness.symbols b/tests/baselines/reference/parserharness.symbols index 92953908f7344..1727bc476ef57 100644 --- a/tests/baselines/reference/parserharness.symbols +++ b/tests/baselines/reference/parserharness.symbols @@ -2379,12 +2379,12 @@ module Harness { >arg : Symbol(arg, Decl(parserharness.ts, 806, 36)) if ((Array.isArray && Array.isArray(arg)) || arg instanceof Array) ->Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), 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, --, --)) ->Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), 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, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >arg : Symbol(arg, Decl(parserharness.ts, 806, 36)) >arg : Symbol(arg, Decl(parserharness.ts, 806, 36)) >Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) diff --git a/tests/baselines/reference/parserharness.types b/tests/baselines/reference/parserharness.types index 498e9bf7ea7ce..df97cfff24591 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: any) => arg is any[] +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >Array : ArrayConstructor ->isArray : (arg: any) => arg is any[] +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >Array.isArray(arg) : boolean ->Array.isArray : (arg: any) => arg is any[] +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >Array : ArrayConstructor ->isArray : (arg: any) => arg is any[] +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >arg : any >arg instanceof Array : boolean >arg : any diff --git a/tests/baselines/reference/partiallyDiscriminantedUnions.symbols b/tests/baselines/reference/partiallyDiscriminantedUnions.symbols index c8096894943d9..c30f45c053aa5 100644 --- a/tests/baselines/reference/partiallyDiscriminantedUnions.symbols +++ b/tests/baselines/reference/partiallyDiscriminantedUnions.symbols @@ -88,9 +88,9 @@ function isShape(s : Shapes): s is Shape { >Shape : Symbol(Shape, Decl(partiallyDiscriminantedUnions.ts, 30, 32)) return !Array.isArray(s); ->Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), 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, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >s : Symbol(s, Decl(partiallyDiscriminantedUnions.ts, 35, 17)) } diff --git a/tests/baselines/reference/partiallyDiscriminantedUnions.types b/tests/baselines/reference/partiallyDiscriminantedUnions.types index f1d44249c0eb2..bbe62c3d0ad56 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: any) => arg is any[] +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >Array : ArrayConstructor ->isArray : (arg: any) => arg is any[] +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >s : Shapes } diff --git a/tests/baselines/reference/promisePermutations.errors.txt b/tests/baselines/reference/promisePermutations.errors.txt index e031002905c3d..020db1211434a 100644 --- a/tests/baselines/reference/promisePermutations.errors.txt +++ b/tests/baselines/reference/promisePermutations.errors.txt @@ -447,7 +447,7 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2769: No overload m !!! error TS2769: The last overload gave the following error. !!! error TS2769: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. !!! error TS2769: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1515:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1516:5: 'catch' is declared here. !!! related TS2771 tests/cases/compiler/promisePermutations.ts:5:5: The last overload is declared here. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok diff --git a/tests/baselines/reference/promisePermutations2.errors.txt b/tests/baselines/reference/promisePermutations2.errors.txt index c6b8f3d344504..e5d43a203e6df 100644 --- a/tests/baselines/reference/promisePermutations2.errors.txt +++ b/tests/baselines/reference/promisePermutations2.errors.txt @@ -351,7 +351,7 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of ~~~~~~~~~ !!! error TS2345: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. !!! error TS2345: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1515:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1516:5: 'catch' is declared here. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; diff --git a/tests/baselines/reference/promisePermutations3.errors.txt b/tests/baselines/reference/promisePermutations3.errors.txt index 7cbd6bafe458c..b3a55815fc49a 100644 --- a/tests/baselines/reference/promisePermutations3.errors.txt +++ b/tests/baselines/reference/promisePermutations3.errors.txt @@ -398,7 +398,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of !!! error TS2769: The last overload gave the following error. !!! error TS2769: Argument of type '(x: any) => IPromise' is not assignable to parameter of type '(error: any) => Promise'. !!! error TS2769: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1515:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1516:5: 'catch' is declared here. !!! related TS2771 tests/cases/compiler/promisePermutations3.ts:7:5: The last overload is declared here. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok @@ -445,5 +445,5 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of ~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ (x: T): IPromise; (x: T, y: T): Promise; }' is not assignable to parameter of type '(value: (x: any) => any) => Promise'. !!! error TS2345: Property 'catch' is missing in type 'IPromise' but required in type 'Promise'. -!!! related TS2728 /.ts/lib.es5.d.ts:1515:5: 'catch' is declared here. +!!! related TS2728 /.ts/lib.es5.d.ts:1516:5: 'catch' is declared here. var s12c = s12.then(testFunction12P, testFunction12, testFunction12); // ok \ No newline at end of file diff --git a/tests/baselines/reference/spreadBooleanRespectsFreshness.symbols b/tests/baselines/reference/spreadBooleanRespectsFreshness.symbols index 90e9a7dace3d1..269f68db30aa7 100644 --- a/tests/baselines/reference/spreadBooleanRespectsFreshness.symbols +++ b/tests/baselines/reference/spreadBooleanRespectsFreshness.symbols @@ -21,9 +21,9 @@ declare let foo2: Foo; foo1 = [...Array.isArray(foo2) ? foo2 : [foo2]]; >foo1 : Symbol(foo1, Decl(spreadBooleanRespectsFreshness.ts, 4, 11)) ->Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --)) +>Array.isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), 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, --, --)) +>isArray : Symbol(ArrayConstructor.isArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) >foo2 : Symbol(foo2, Decl(spreadBooleanRespectsFreshness.ts, 5, 11)) >foo2 : Symbol(foo2, Decl(spreadBooleanRespectsFreshness.ts, 5, 11)) >foo2 : Symbol(foo2, Decl(spreadBooleanRespectsFreshness.ts, 5, 11)) diff --git a/tests/baselines/reference/spreadBooleanRespectsFreshness.types b/tests/baselines/reference/spreadBooleanRespectsFreshness.types index cd20dc31944b6..cc63eee05ccc8 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: any) => arg is any[] +>Array.isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >Array : ArrayConstructor ->isArray : (arg: any) => arg is any[] +>isArray : { (arg: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; } >foo2 : Foo >foo2 : FooArray >[foo2] : FooBase[]