diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index e111d36d117ad..25450e04e6f6e 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -1376,7 +1376,7 @@ interface ArrayConstructor { (arrayLength?: number): any[]; (arrayLength: number): T[]; (...items: T[]): T[]; - isArray(arg: any): arg is any[]; + isArray(arg: T | {}): arg is T extends readonly any[] ? readonly any[] : any[]; readonly prototype: any[]; } diff --git a/src/blank.ts b/tests/cases/compiler/consistentUnionSubtypeReduction.ts similarity index 56% rename from src/blank.ts rename to tests/cases/compiler/consistentUnionSubtypeReduction.ts index 869667a9d4806..53f0f9782fc92 100644 --- a/src/blank.ts +++ b/tests/cases/compiler/consistentUnionSubtypeReduction.ts @@ -1,3 +1,5 @@ +// https://github.com/microsoft/TypeScript/issues/31155 + declare const MyArray: { isArray(arg: T | {}): arg is T extends readonly any[] ? readonly any[] : any[]; }; @@ -7,23 +9,23 @@ declare const b: string[] | string; declare const c: unknown; if (MyArray.isArray(a)) { - a; + a; // readonly string[] } else { - a; + a; // string } -a; +a; // readonly string[] | string; if (MyArray.isArray(b)) { - b; + b; // string[] | string; } else { - b; + b; // string } -b; +b; // string[] | string; if (MyArray.isArray(c)) { - c; + c; // any[] } @@ -33,22 +35,22 @@ function f(x: T) { const c: T = null!; if (MyArray.isArray(a)) { - a; + a; // readonly T[] } else { - a; + a; // string } - a; + a; // readonly T[] | string; if (MyArray.isArray(b)) { - b; + b; // T[] } else { - b; + b; // string } b; if (MyArray.isArray(c)) { - c; + c; // T & (T extends readonly any[] ? readonly any[] : any[]) } }