File: intersectionTypeMembers.types

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (208 lines) | stat: -rw-r--r-- 5,362 bytes parent folder | download | duplicates (3)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
=== tests/cases/conformance/types/intersection/intersectionTypeMembers.ts ===
// An intersection type has those members that are present in any of its constituent types,
// with types that are intersections of the respective members in the constituent types

interface A { a: string }
>a : string

interface B { b: string }
>b : string

interface C { c: string }
>c : string

var abc: A & B & C;
>abc : A & B & C

abc.a = "hello";
>abc.a = "hello" : "hello"
>abc.a : string
>abc : A & B & C
>a : string
>"hello" : "hello"

abc.b = "hello";
>abc.b = "hello" : "hello"
>abc.b : string
>abc : A & B & C
>b : string
>"hello" : "hello"

abc.c = "hello";
>abc.c = "hello" : "hello"
>abc.c : string
>abc : A & B & C
>c : string
>"hello" : "hello"

interface X { x: A }
>x : A

interface Y { x: B }
>x : B

interface Z { x: C }
>x : C

var xyz: X & Y & Z;
>xyz : X & Y & Z

xyz.x.a = "hello";
>xyz.x.a = "hello" : "hello"
>xyz.x.a : string
>xyz.x : A & B & C
>xyz : X & Y & Z
>x : A & B & C
>a : string
>"hello" : "hello"

xyz.x.b = "hello";
>xyz.x.b = "hello" : "hello"
>xyz.x.b : string
>xyz.x : A & B & C
>xyz : X & Y & Z
>x : A & B & C
>b : string
>"hello" : "hello"

xyz.x.c = "hello";
>xyz.x.c = "hello" : "hello"
>xyz.x.c : string
>xyz.x : A & B & C
>xyz : X & Y & Z
>x : A & B & C
>c : string
>"hello" : "hello"

type F1 = (x: string) => string;
>F1 : (x: string) => string
>x : string

type F2 = (x: number) => number;
>F2 : (x: number) => number
>x : number

var f: F1 & F2;
>f : F1 & F2

var s = f("hello");
>s : string
>f("hello") : string
>f : F1 & F2
>"hello" : "hello"

var n = f(42);
>n : number
>f(42) : number
>f : F1 & F2
>42 : 42

interface D {
    nested: { doublyNested: { d: string; }, different: { e: number } };
>nested : { doublyNested: {    d: string;}; different: {    e: number;}; }
>doublyNested : { d: string; }
>d : string
>different : { e: number; }
>e : number
}
interface E {
    nested: { doublyNested: { f: string; }, other: {g: number } };
>nested : { doublyNested: {    f: string;}; other: {    g: number;}; }
>doublyNested : { f: string; }
>f : string
>other : { g: number; }
>g : number
}
const de: D & E = {
>de : D & E
>{    nested: {        doublyNested: {            d: 'yes',            f: 'no'        },        different: { e: 12 },        other: { g: 101 }    }} : { nested: { doublyNested: { d: string; f: string; }; different: { e: number; }; other: { g: number; }; }; }

    nested: {
>nested : { doublyNested: { d: string; f: string; }; different: { e: number; }; other: { g: number; }; }
>{        doublyNested: {            d: 'yes',            f: 'no'        },        different: { e: 12 },        other: { g: 101 }    } : { doublyNested: { d: string; f: string; }; different: { e: number; }; other: { g: number; }; }

        doublyNested: {
>doublyNested : { d: string; f: string; }
>{            d: 'yes',            f: 'no'        } : { d: string; f: string; }

            d: 'yes',
>d : string
>'yes' : "yes"

            f: 'no'
>f : string
>'no' : "no"

        },
        different: { e: 12 },
>different : { e: number; }
>{ e: 12 } : { e: number; }
>e : number
>12 : 12

        other: { g: 101 }
>other : { g: number; }
>{ g: 101 } : { g: number; }
>g : number
>101 : 101
    }
}

// Additional test case with >2 doubly nested members so fix for #31441 is tested w/ excess props
interface F {
    nested: { doublyNested: { g: string; } }
>nested : { doublyNested: {    g: string;}; }
>doublyNested : { g: string; }
>g : string
}

interface G {
    nested: { doublyNested: { h: string; } }
>nested : { doublyNested: {    h: string;}; }
>doublyNested : { h: string; }
>h : string
}

const defg: D & E & F & G = {
>defg : D & E & F & G
>{    nested: {        doublyNested: {            d: 'yes',            f: 'no',            g: 'ok',            h: 'affirmative'        },        different: { e: 12 },        other: { g: 101 }    }} : { nested: { doublyNested: { d: string; f: string; g: string; h: string; }; different: { e: number; }; other: { g: number; }; }; }

    nested: {
>nested : { doublyNested: { d: string; f: string; g: string; h: string; }; different: { e: number; }; other: { g: number; }; }
>{        doublyNested: {            d: 'yes',            f: 'no',            g: 'ok',            h: 'affirmative'        },        different: { e: 12 },        other: { g: 101 }    } : { doublyNested: { d: string; f: string; g: string; h: string; }; different: { e: number; }; other: { g: number; }; }

        doublyNested: {
>doublyNested : { d: string; f: string; g: string; h: string; }
>{            d: 'yes',            f: 'no',            g: 'ok',            h: 'affirmative'        } : { d: string; f: string; g: string; h: string; }

            d: 'yes',
>d : string
>'yes' : "yes"

            f: 'no',
>f : string
>'no' : "no"

            g: 'ok',
>g : string
>'ok' : "ok"

            h: 'affirmative'
>h : string
>'affirmative' : "affirmative"

        },
        different: { e: 12 },
>different : { e: number; }
>{ e: 12 } : { e: number; }
>e : number
>12 : 12

        other: { g: 101 }
>other : { g: number; }
>{ g: 101 } : { g: number; }
>g : number
>101 : 101
    }
}