File: objectSpreadInference.types

package info (click to toggle)
node-typescript 2.1.5-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 203,960 kB
  • sloc: sh: 11; makefile: 5
file content (118 lines) | stat: -rw-r--r-- 2,636 bytes parent folder | download | duplicates (2)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
=== tests/cases/conformance/types/spread/objectSpreadInference.ts ===
interface Result<T,U,V> {
>Result : Result<T, U, V>
>T : T
>U : U
>V : V

    t: T;
>t : T
>T : T

    u: U;
>u : U
>U : U

    v: V;
>v : V
>V : V
}
declare function infer<T,U,V>(tuv: { ...T, ...U, a: V }): { t: T, u: U, v: V };
>infer : <T, U, V>(tuv: { ...T; ...U; a: V; }) => { t: T; u: U; v: V; }
>T : T
>U : U
>V : V
>tuv : { ...T; ...U; a: V; }
>T : T
>U : U
>a : V
>V : V
>t : T
>T : T
>u : U
>U : U
>v : V
>V : V

declare function infer2<T,U,V>(utv: { ...U, a: V, ...T }): { t: T, u: U, v: V };
>infer2 : <T, U, V>(utv: { ...U; a: V; ...T }) => { t: T; u: U; v: V; }
>T : T
>U : U
>V : V
>utv : { ...U; a: V; ...T }
>U : U
>a : V
>V : V
>T : T
>t : T
>T : T
>u : U
>U : U
>v : V
>V : V

function generic<W, X, Y>(w: W, x: X, y: Y) {
>generic : <W, X, Y>(w: W, x: X, y: Y) => { t: {}; u: {}; v: {}; }
>W : W
>X : X
>Y : Y
>w : W
>W : W
>x : X
>X : X
>y : Y
>Y : Y

    // should infer { t: {}, u: {}, v: {} } because there is no trailing type parameter
    return infer({ ...w, ...x, a: y, b: "different type" });
>infer({ ...w, ...x, a: y, b: "different type" }) : { t: {}; u: {}; v: {}; }
>infer : <T, U, V>(tuv: { ...T; ...U; a: V; }) => { t: T; u: U; v: V; }
>{ ...w, ...x, a: y, b: "different type" } : { ...W; ...X; a: Y; b: string; }
>w : any
>x : any
>a : Y
>y : Y
>b : string
>"different type" : "different type"
}
let b: { b: number };
>b : { b: number; }
>b : number

let c: { c: number };
>c : { c: number; }
>c : number

// can only infer { t: {}, u: {}, v: {} }
let i1 = infer({ ...b, ...c, a: 12 });
>i1 : { t: {}; u: {}; v: {}; }
>infer({ ...b, ...c, a: 12 }) : { t: {}; u: {}; v: {}; }
>infer : <T, U, V>(tuv: { ...T; ...U; a: V; }) => { t: T; u: U; v: V; }
>{ ...b, ...c, a: 12 } : { a: number; c: number; b: number; }
>b : any
>c : any
>a : number
>12 : 12

// can only infer { t: {}, u: {}, v: {} }
let i2 = infer2({ ...b, ...c, a: 12 });
>i2 : { t: {}; u: {}; v: {}; }
>infer2({ ...b, ...c, a: 12 }) : { t: {}; u: {}; v: {}; }
>infer2 : <T, U, V>(utv: { ...U; a: V; ...T }) => { t: T; u: U; v: V; }
>{ ...b, ...c, a: 12 } : { a: number; c: number; b: number; }
>b : any
>c : any
>a : number
>12 : 12

// can only infer { t: {}, u: {}, v: {} }
let i3 = generic(b, c, { a: 12 });
>i3 : { t: {}; u: {}; v: {}; }
>generic(b, c, { a: 12 }) : { t: {}; u: {}; v: {}; }
>generic : <W, X, Y>(w: W, x: X, y: Y) => { t: {}; u: {}; v: {}; }
>b : { b: number; }
>c : { c: number; }
>{ a: 12 } : { a: number; }
>a : number
>12 : 12