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
|
//// [genericCallWithTupleType.ts]
interface I<T, U> {
tuple1: [T, U];
}
var i1: I<string, number>;
var i2: I<{}, {}>;
// no error
i1.tuple1 = ["foo", 5];
var e1 = i1.tuple1[0]; // string
var e2 = i1.tuple1[1]; // number
i1.tuple1 = ["foo", 5, false, true];
var e3 = i1.tuple1[2]; // {}
i1.tuple1[3] = { a: "string" };
var e4 = i1.tuple1[3]; // {}
i2.tuple1 = ["foo", 5];
i2.tuple1 = ["foo", "bar"];
i2.tuple1 = [5, "bar"];
i2.tuple1 = [{}, {}];
// error
i1.tuple1 = [5, "foo"];
i1.tuple1 = [{}, {}];
i2.tuple1 = [{}];
//// [genericCallWithTupleType.js]
var i1;
var i2;
// no error
i1.tuple1 = ["foo", 5];
var e1 = i1.tuple1[0]; // string
var e2 = i1.tuple1[1]; // number
i1.tuple1 = ["foo", 5, false, true];
var e3 = i1.tuple1[2]; // {}
i1.tuple1[3] = { a: "string" };
var e4 = i1.tuple1[3]; // {}
i2.tuple1 = ["foo", 5];
i2.tuple1 = ["foo", "bar"];
i2.tuple1 = [5, "bar"];
i2.tuple1 = [{}, {}];
// error
i1.tuple1 = [5, "foo"];
i1.tuple1 = [{}, {}];
i2.tuple1 = [{}];
|