File: genericCallWithTupleType.js

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (46 lines) | stat: -rw-r--r-- 1,006 bytes parent folder | download | duplicates (7)
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 = [{}];