1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
//// [unionWithIndexSignature.ts]
interface NumList {
kind: 'n';
[x: number]: number;
}
interface StrList {
kind: 's';
[x: number]: string;
}
export function foo<T extends NumList | StrList>(arr: T & (NumList | StrList)) {
let zz = arr[1]; // Error
}
// Repro from #38102
export type TypedArray = Int32Array | Uint8Array;
export function isTypedArray(a: {}): a is Int32Array | Uint8Array {
return a instanceof Int32Array || a instanceof Uint8Array;
}
export function flatten<T extends number|TypedArray>(arr: T) {
if (isTypedArray(arr)) {
arr[1];
}
}
//// [unionWithIndexSignature.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.flatten = exports.isTypedArray = exports.foo = void 0;
function foo(arr) {
var zz = arr[1]; // Error
}
exports.foo = foo;
function isTypedArray(a) {
return a instanceof Int32Array || a instanceof Uint8Array;
}
exports.isTypedArray = isTypedArray;
function flatten(arr) {
if (isTypedArray(arr)) {
arr[1];
}
}
exports.flatten = flatten;
|