diff --git a/src/lib/es2015.iterable.d.ts b/src/lib/es2015.iterable.d.ts index 00a0ff820ca09..5bf226fc469b0 100644 --- a/src/lib/es2015.iterable.d.ts +++ b/src/lib/es2015.iterable.d.ts @@ -62,6 +62,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 33bbb99147490..2d3df652f559e 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1492,7 +1492,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/baselines/reference/arrayDestructuringInSwitch1.symbols b/tests/baselines/reference/arrayDestructuringInSwitch1.symbols index 1218fb03d02f2..c9d1e8d340409 100644 --- a/tests/baselines/reference/arrayDestructuringInSwitch1.symbols +++ b/tests/baselines/reference/arrayDestructuringInSwitch1.symbols @@ -16,9 +16,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 ec8ad2209e0b2..fb1755a187270 100644 --- a/tests/baselines/reference/arrayDestructuringInSwitch1.types +++ b/tests/baselines/reference/arrayDestructuringInSwitch1.types @@ -18,12 +18,12 @@ 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 > : ^^^^^^^^^^ diff --git a/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.symbols b/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.symbols index 75532047fccd6..573702aa3ac91 100644 --- a/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.symbols +++ b/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.symbols @@ -81,9 +81,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 b316511915c45..b84ab3564e8f0 100644 --- a/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types +++ b/tests/baselines/reference/declarationsWithRecursiveInternalTypesProduceUniqueTypeParams.types @@ -119,12 +119,12 @@ export const updateIfChanged = (t: T) => { > : ^^^^^^^^^^^^^^^^ >Array.isArray(u) : boolean > : ^^^^^^^ ->Array.isArray : (arg: any) => arg is any[] -> : ^ ^^ ^^^^^ +>Array.isArray : { (arg: ArrayLike): arg is readonly T_1[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T_1[]; } +> : ^^^^^^^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^^^^^^ ^^ ^^^ ^^^ >Array : ArrayConstructor > : ^^^^^^^^^^^^^^^^ ->isArray : (arg: any) => arg is any[] -> : ^ ^^ ^^^^^ +>isArray : { (arg: ArrayLike): arg is readonly T_1[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T_1[]; } +> : ^^^^^^^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^^^^^^ ^^ ^^^ ^^^ >u : U > : ^ >[] : undefined[] diff --git a/tests/baselines/reference/fixSignatureCaching.symbols b/tests/baselines/reference/fixSignatureCaching.symbols index 36f32a0d558ca..a89ef6934aba8 100644 --- a/tests/baselines/reference/fixSignatureCaching.symbols +++ b/tests/baselines/reference/fixSignatureCaching.symbols @@ -798,9 +798,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, --, --)) diff --git a/tests/baselines/reference/fixSignatureCaching.types b/tests/baselines/reference/fixSignatureCaching.types index 4251529b6a09e..78e33443a9fce 100644 --- a/tests/baselines/reference/fixSignatureCaching.types +++ b/tests/baselines/reference/fixSignatureCaching.types @@ -1660,12 +1660,12 @@ define(function () { > : ^^^^^^^^^^^^^^^^ 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 diff --git a/tests/baselines/reference/inKeywordTypeguard(strict=false).symbols b/tests/baselines/reference/inKeywordTypeguard(strict=false).symbols index 28a7af3d7b9d5..0af3cea0a661a 100644 --- a/tests/baselines/reference/inKeywordTypeguard(strict=false).symbols +++ b/tests/baselines/reference/inKeywordTypeguard(strict=false).symbols @@ -891,9 +891,9 @@ function test1>(obj: T) { >T : Symbol(T, Decl(inKeywordTypeguard.ts, 357, 15)) if (Array.isArray(obj) || 'length' in obj) { ->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, --, --)) >obj : Symbol(obj, Decl(inKeywordTypeguard.ts, 357, 54)) >obj : Symbol(obj, Decl(inKeywordTypeguard.ts, 357, 54)) @@ -914,9 +914,9 @@ function test2>(obj: T) { >T : Symbol(T, Decl(inKeywordTypeguard.ts, 366, 15)) if (Array.isArray(obj)) { ->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, --, --)) >obj : Symbol(obj, Decl(inKeywordTypeguard.ts, 366, 54)) obj; // T & any[] diff --git a/tests/baselines/reference/inKeywordTypeguard(strict=false).types b/tests/baselines/reference/inKeywordTypeguard(strict=false).types index eaf32e71c8c0b..f01d67839a94d 100644 --- a/tests/baselines/reference/inKeywordTypeguard(strict=false).types +++ b/tests/baselines/reference/inKeywordTypeguard(strict=false).types @@ -1,5 +1,8 @@ //// [tests/cases/compiler/inKeywordTypeguard.ts] //// +=== Performance Stats === +Type Count: 1,000 + === inKeywordTypeguard.ts === class A { a: string; } >A : A @@ -1710,12 +1713,12 @@ function test1>(obj: T) { > : ^^^^^^^ >Array.isArray(obj) : boolean > : ^^^^^^^ ->Array.isArray : (arg: any) => arg is any[] -> : ^ ^^ ^^^^^ +>Array.isArray : { (arg: ArrayLike): arg is readonly T_1[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T_1[]; } +> : ^^^^^^^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^^^^^^ ^^ ^^^ ^^^ >Array : ArrayConstructor > : ^^^^^^^^^^^^^^^^ ->isArray : (arg: any) => arg is any[] -> : ^ ^^ ^^^^^ +>isArray : { (arg: ArrayLike): arg is readonly T_1[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T_1[]; } +> : ^^^^^^^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^^^^^^ ^^ ^^^ ^^^ >obj : any[] | Record > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ >'length' in obj : boolean @@ -1745,12 +1748,12 @@ function test2>(obj: T) { if (Array.isArray(obj)) { >Array.isArray(obj) : boolean > : ^^^^^^^ ->Array.isArray : (arg: any) => arg is any[] -> : ^ ^^ ^^^^^ +>Array.isArray : { (arg: ArrayLike): arg is readonly T_1[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T_1[]; } +> : ^^^^^^^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^^^^^^ ^^ ^^^ ^^^ >Array : ArrayConstructor > : ^^^^^^^^^^^^^^^^ ->isArray : (arg: any) => arg is any[] -> : ^ ^^ ^^^^^ +>isArray : { (arg: ArrayLike): arg is readonly T_1[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T_1[]; } +> : ^^^^^^^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^^^^^^ ^^ ^^^ ^^^ >obj : any[] | Record > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/baselines/reference/inKeywordTypeguard(strict=true).symbols b/tests/baselines/reference/inKeywordTypeguard(strict=true).symbols index 28a7af3d7b9d5..0af3cea0a661a 100644 --- a/tests/baselines/reference/inKeywordTypeguard(strict=true).symbols +++ b/tests/baselines/reference/inKeywordTypeguard(strict=true).symbols @@ -891,9 +891,9 @@ function test1>(obj: T) { >T : Symbol(T, Decl(inKeywordTypeguard.ts, 357, 15)) if (Array.isArray(obj) || 'length' in obj) { ->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, --, --)) >obj : Symbol(obj, Decl(inKeywordTypeguard.ts, 357, 54)) >obj : Symbol(obj, Decl(inKeywordTypeguard.ts, 357, 54)) @@ -914,9 +914,9 @@ function test2>(obj: T) { >T : Symbol(T, Decl(inKeywordTypeguard.ts, 366, 15)) if (Array.isArray(obj)) { ->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, --, --)) >obj : Symbol(obj, Decl(inKeywordTypeguard.ts, 366, 54)) obj; // T & any[] diff --git a/tests/baselines/reference/inKeywordTypeguard(strict=true).types b/tests/baselines/reference/inKeywordTypeguard(strict=true).types index 118e1c698a636..0c7822121d379 100644 --- a/tests/baselines/reference/inKeywordTypeguard(strict=true).types +++ b/tests/baselines/reference/inKeywordTypeguard(strict=true).types @@ -1713,12 +1713,12 @@ function test1>(obj: T) { > : ^^^^^^^ >Array.isArray(obj) : boolean > : ^^^^^^^ ->Array.isArray : (arg: any) => arg is any[] -> : ^ ^^ ^^^^^ +>Array.isArray : { (arg: ArrayLike): arg is readonly T_1[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T_1[]; } +> : ^^^^^^^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^^^^^^ ^^ ^^^ ^^^ >Array : ArrayConstructor > : ^^^^^^^^^^^^^^^^ ->isArray : (arg: any) => arg is any[] -> : ^ ^^ ^^^^^ +>isArray : { (arg: ArrayLike): arg is readonly T_1[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T_1[]; } +> : ^^^^^^^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^^^^^^ ^^ ^^^ ^^^ >obj : any[] | Record > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ >'length' in obj : boolean @@ -1748,12 +1748,12 @@ function test2>(obj: T) { if (Array.isArray(obj)) { >Array.isArray(obj) : boolean > : ^^^^^^^ ->Array.isArray : (arg: any) => arg is any[] -> : ^ ^^ ^^^^^ +>Array.isArray : { (arg: ArrayLike): arg is readonly T_1[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T_1[]; } +> : ^^^^^^^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^^^^^^ ^^ ^^^ ^^^ >Array : ArrayConstructor > : ^^^^^^^^^^^^^^^^ ->isArray : (arg: any) => arg is any[] -> : ^ ^^ ^^^^^ +>isArray : { (arg: ArrayLike): arg is readonly T_1[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T_1[]; } +> : ^^^^^^^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^^^^^^ ^^ ^^^ ^^^ >obj : any[] | Record > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/baselines/reference/instantiationExpressions.types b/tests/baselines/reference/instantiationExpressions.types index 4b3156a650df7..9e8db44b173e7 100644 --- a/tests/baselines/reference/instantiationExpressions.types +++ b/tests/baselines/reference/instantiationExpressions.types @@ -95,18 +95,18 @@ function f2() { > : ^^^^^^^^^^^^^^^^ 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[]; } -> : ^^^ ^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^^ ->Array : { (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 : { (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[]; } -> : ^^^^^^^^^^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^^ ->Array : { 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 : { isArray(arg: ArrayLike): arg is readonly T[]; isArray(arg: unknown): arg is any[]; readonly prototype: any[]; } +> : ^^^^^^^^^^ ^^ ^^ ^^^ ^^^^^^^^^^ ^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^ ^^^ >Array : ArrayConstructor > : ^^^^^^^^^^^^^^^^ } diff --git a/tests/baselines/reference/isArray.errors.txt b/tests/baselines/reference/isArray.errors.txt new file mode 100644 index 0000000000000..f9c224c966ffe --- /dev/null +++ b/tests/baselines/reference/isArray.errors.txt @@ -0,0 +1,71 @@ +isArray.ts(15,9): error TS4104: The type 'readonly string[]' is 'readonly' and cannot be assigned to the mutable type 'string[]'. +isArray.ts(26,9): error TS2322: Type 'readonly string[]' is not assignable to type 'readonly void[]'. + Type 'string' is not assignable to type 'void'. +isArray.ts(32,9): error TS2322: Type 'readonly string[]' is not assignable to type 'readonly void[]'. + Type 'string' is not assignable to type 'void'. +isArray.ts(41,9): error TS2322: Type 'any[]' is not assignable to type 'void'. +isArray.ts(47,9): error TS2322: Type 'any[]' is not assignable to type 'void'. + + +==== 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[]'. +!!! error TS2322: Type 'string' is not assignable to type '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 af7d23275f121..0a5c85dd93cb6 100644 --- a/tests/baselines/reference/isArray.js +++ b/tests/baselines/reference/isArray.js @@ -1,21 +1,83 @@ //// [tests/cases/compiler/isArray.ts] //// //// [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 7a6886d94a41f..2a390d6277502 100644 --- a/tests/baselines/reference/isArray.symbols +++ b/tests/baselines/reference/isArray.symbols @@ -1,24 +1,126 @@ //// [tests/cases/compiler/isArray.ts] //// === 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 711b042b43206..8a4c31d1cc4cc 100644 --- a/tests/baselines/reference/isArray.types +++ b/tests/baselines/reference/isArray.types @@ -1,39 +1,190 @@ //// [tests/cases/compiler/isArray.ts] //// === 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: 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[]; } +> : ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^ ^^ ^^ ^^^ ^^^ +>mutable : string | string[] +> : ^^^^^^^^^^^^^^^^^ - maybeArray.length; // OK ->maybeArray.length : number -> : ^^^^^^ ->maybeArray : number[] + 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[] > : ^^^^^^^^ ->length : number -> : ^^^^^^ +>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: ArrayLike): arg is readonly T[]; (arg: unknown): arg is any[]; (arg: Iterable): arg is readonly T[]; } +> : ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^ ^^ ^^ ^^^ ^^^ +>iterable : string | Iterable +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ + + 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.symbols b/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.symbols index fc68e805a92fe..04c42d10e1ef6 100644 --- a/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.symbols +++ b/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.symbols @@ -25,9 +25,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 7a4646f943e28..3c60f45e838fa 100644 --- a/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.types +++ b/tests/baselines/reference/javascriptThisAssignmentInStaticBlock.types @@ -39,14 +39,14 @@ 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) => arg is any[] @@ -56,8 +56,8 @@ class ElementsArray extends Array { >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 3e21195da6f7e..ecd10a7e1e678 100644 --- a/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.symbols +++ b/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.symbols @@ -63,9 +63,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)) @@ -76,9 +76,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 a2a7572599f0f..950a087da5fb6 100644 --- a/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.types +++ b/tests/baselines/reference/literalFreshnessPropagationOnNarrowing.types @@ -96,12 +96,12 @@ function f2() { > : ^^^^^^^^^^^^^^^^^^ >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)[] @@ -125,12 +125,12 @@ function f2() { > : ^^^^^^^^^^^^^^^^^^ >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)[] diff --git a/tests/baselines/reference/malformedTags.symbols b/tests/baselines/reference/malformedTags.symbols index 0a35713fc9497..fc2ff0ec4cebe 100644 --- a/tests/baselines/reference/malformedTags.symbols +++ b/tests/baselines/reference/malformedTags.symbols @@ -8,7 +8,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 e873e70510a8e..16381ab2d037f 100644 --- a/tests/baselines/reference/malformedTags.types +++ b/tests/baselines/reference/malformedTags.types @@ -9,10 +9,10 @@ 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/narrowByBooleanComparison.symbols b/tests/baselines/reference/narrowByBooleanComparison.symbols index 466d5936028bd..34eac285a2d9f 100644 --- a/tests/baselines/reference/narrowByBooleanComparison.symbols +++ b/tests/baselines/reference/narrowByBooleanComparison.symbols @@ -121,9 +121,9 @@ function test3(foo: unknown) { if (typeof foo !== 'string' && Array.isArray(foo) === false) { >foo : Symbol(foo, Decl(narrowByBooleanComparison.ts, 50, 15)) ->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, --, --)) >foo : Symbol(foo, Decl(narrowByBooleanComparison.ts, 50, 15)) throw new Error('Not a string or an array'); diff --git a/tests/baselines/reference/narrowByBooleanComparison.types b/tests/baselines/reference/narrowByBooleanComparison.types index cbfe5818cfdbf..9ce7622c9c61b 100644 --- a/tests/baselines/reference/narrowByBooleanComparison.types +++ b/tests/baselines/reference/narrowByBooleanComparison.types @@ -232,12 +232,12 @@ function test3(foo: unknown) { > : ^^^^^^^ >Array.isArray(foo) : 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[]; } +> : ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^ >foo : unknown > : ^^^^^^^ >false : false diff --git a/tests/baselines/reference/narrowingAssignmentReadonlyRespectsAssertion.symbols b/tests/baselines/reference/narrowingAssignmentReadonlyRespectsAssertion.symbols index 669b2bd6fdda7..0aea98880b02e 100644 --- a/tests/baselines/reference/narrowingAssignmentReadonlyRespectsAssertion.symbols +++ b/tests/baselines/reference/narrowingAssignmentReadonlyRespectsAssertion.symbols @@ -84,9 +84,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 43415e124c617..8a1cdad21787d 100644 --- a/tests/baselines/reference/narrowingAssignmentReadonlyRespectsAssertion.types +++ b/tests/baselines/reference/narrowingAssignmentReadonlyRespectsAssertion.types @@ -164,12 +164,12 @@ 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)[] > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/baselines/reference/narrowingMutualSubtypes.symbols b/tests/baselines/reference/narrowingMutualSubtypes.symbols index 67f6c7a9c973d..437fb120a018b 100644 --- a/tests/baselines/reference/narrowingMutualSubtypes.symbols +++ b/tests/baselines/reference/narrowingMutualSubtypes.symbols @@ -263,9 +263,9 @@ function checksArrayOrObject1(obj: Record | Record[]) // "accidentally" guards the first branch on the length if (Array.isArray(obj) && obj.length) { ->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, --, --)) >obj : Symbol(obj, Decl(narrowingMutualSubtypes.ts, 104, 30)) >obj.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) >obj : Symbol(obj, Decl(narrowingMutualSubtypes.ts, 104, 30)) @@ -318,9 +318,9 @@ function checksArrayOrObject2(obj: Record | Record[]) >Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) if (Array.isArray(obj)) { ->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, --, --)) >obj : Symbol(obj, Decl(narrowingMutualSubtypes.ts, 123, 30)) // obj should only be an array type here diff --git a/tests/baselines/reference/narrowingMutualSubtypes.types b/tests/baselines/reference/narrowingMutualSubtypes.types index fdb0711a36788..e397925c4733a 100644 --- a/tests/baselines/reference/narrowingMutualSubtypes.types +++ b/tests/baselines/reference/narrowingMutualSubtypes.types @@ -391,12 +391,12 @@ function checksArrayOrObject1(obj: Record | Record[]) > : ^^^^^^^^^^^^^^ >Array.isArray(obj) : 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[]; } +> : ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^ >obj : Record | Record[] > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >obj.length : number @@ -491,12 +491,12 @@ function checksArrayOrObject2(obj: Record | Record[]) if (Array.isArray(obj)) { >Array.isArray(obj) : 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[]; } +> : ^^^ ^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^ >obj : Record | Record[] > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/baselines/reference/noIterationTypeErrorsInCFA.symbols b/tests/baselines/reference/noIterationTypeErrorsInCFA.symbols index 211e351019cc1..d7fba009ce82a 100644 --- a/tests/baselines/reference/noIterationTypeErrorsInCFA.symbols +++ b/tests/baselines/reference/noIterationTypeErrorsInCFA.symbols @@ -14,9 +14,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 4 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 0e649fb42fd6b..fdff17765173b 100644 --- a/tests/baselines/reference/noIterationTypeErrorsInCFA.types +++ b/tests/baselines/reference/noIterationTypeErrorsInCFA.types @@ -17,12 +17,12 @@ export function doRemove(dds: F | F[]) { > : ^^^^^^^ >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[] > : ^^^^^^^ diff --git a/tests/baselines/reference/parserharness.symbols b/tests/baselines/reference/parserharness.symbols index 1bab54ca5c5b5..0444a688e72c1 100644 --- a/tests/baselines/reference/parserharness.symbols +++ b/tests/baselines/reference/parserharness.symbols @@ -2381,12 +2381,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 0326d8453ba19..57c506147f491 100644 --- a/tests/baselines/reference/parserharness.types +++ b/tests/baselines/reference/parserharness.types @@ -5030,20 +5030,20 @@ module Harness { > : ^^^^^^^ >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 diff --git a/tests/baselines/reference/partiallyDiscriminantedUnions.symbols b/tests/baselines/reference/partiallyDiscriminantedUnions.symbols index 0fde248eb2a2e..d8ebee34c5a33 100644 --- a/tests/baselines/reference/partiallyDiscriminantedUnions.symbols +++ b/tests/baselines/reference/partiallyDiscriminantedUnions.symbols @@ -90,9 +90,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 cdead438ff1f2..a3a23d80fd6a3 100644 --- a/tests/baselines/reference/partiallyDiscriminantedUnions.types +++ b/tests/baselines/reference/partiallyDiscriminantedUnions.types @@ -112,12 +112,12 @@ function isShape(s : Shapes): s is Shape { > : ^^^^^^^ >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/spreadBooleanRespectsFreshness.symbols b/tests/baselines/reference/spreadBooleanRespectsFreshness.symbols index 194d9418ab1f2..13abaca32dfda 100644 --- a/tests/baselines/reference/spreadBooleanRespectsFreshness.symbols +++ b/tests/baselines/reference/spreadBooleanRespectsFreshness.symbols @@ -23,9 +23,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 68289d8a47aaa..85e658d2152b8 100644 --- a/tests/baselines/reference/spreadBooleanRespectsFreshness.types +++ b/tests/baselines/reference/spreadBooleanRespectsFreshness.types @@ -36,12 +36,12 @@ foo1 = [...Array.isArray(foo2) ? foo2 : [foo2]]; > : ^^^^^^^^ >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 diff --git a/tests/baselines/reference/unknownControlFlow.symbols b/tests/baselines/reference/unknownControlFlow.symbols index 8216110b80049..f07bbfed00bae 100644 --- a/tests/baselines/reference/unknownControlFlow.symbols +++ b/tests/baselines/reference/unknownControlFlow.symbols @@ -588,13 +588,13 @@ function deepEquals(a: T, b: T): boolean { return false; } if (Array.isArray(a) || Array.isArray(b)) { ->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, --, --)) >a : Symbol(a, Decl(unknownControlFlow.ts, 247, 23)) ->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, --, --)) >b : Symbol(b, Decl(unknownControlFlow.ts, 247, 28)) return false; diff --git a/tests/baselines/reference/unknownControlFlow.types b/tests/baselines/reference/unknownControlFlow.types index 2c84aa0d19d3e..ee64ccc53b60f 100644 --- a/tests/baselines/reference/unknownControlFlow.types +++ b/tests/baselines/reference/unknownControlFlow.types @@ -959,22 +959,22 @@ function deepEquals(a: T, b: T): boolean { > : ^^^^^^^ >Array.isArray(a) : boolean > : ^^^^^^^ ->Array.isArray : (arg: any) => arg is any[] -> : ^ ^^ ^^^^^ +>Array.isArray : { (arg: ArrayLike): arg is readonly T_1[]; (arg: unknown): arg is any[]; } +> : ^^^^^^^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^ >Array : ArrayConstructor > : ^^^^^^^^^^^^^^^^ ->isArray : (arg: any) => arg is any[] -> : ^ ^^ ^^^^^ +>isArray : { (arg: ArrayLike): arg is readonly T_1[]; (arg: unknown): arg is any[]; } +> : ^^^^^^^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^ >a : T & object > : ^^^^^^^^^^ >Array.isArray(b) : boolean > : ^^^^^^^ ->Array.isArray : (arg: any) => arg is any[] -> : ^ ^^ ^^^^^ +>Array.isArray : { (arg: ArrayLike): arg is readonly T_1[]; (arg: unknown): arg is any[]; } +> : ^^^^^^^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^ >Array : ArrayConstructor > : ^^^^^^^^^^^^^^^^ ->isArray : (arg: any) => arg is any[] -> : ^ ^^ ^^^^^ +>isArray : { (arg: ArrayLike): arg is readonly T_1[]; (arg: unknown): arg is any[]; } +> : ^^^^^^^^ ^^ ^^^ ^^^ ^^ ^^^ ^^^ >b : T & object > : ^^^^^^^^^^ 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