File: unionTypeWithIndexSignature.types

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (155 lines) | stat: -rw-r--r-- 3,131 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
=== tests/cases/conformance/types/union/unionTypeWithIndexSignature.ts ===
type Two = { foo: { bar: true }, baz: true } | { [s: string]: string };
>Two : { foo: {    bar: true;}; baz: true; } | { [s: string]: string; }
>foo : { bar: true; }
>bar : true
>true : true
>baz : true
>true : true
>s : string

declare var u: Two
>u : Two

u.foo = 'bye'
>u.foo = 'bye' : "bye"
>u.foo : string | { bar: true; }
>u : Two
>foo : string | { bar: true; }
>'bye' : "bye"

u.baz = 'hi'
>u.baz = 'hi' : "hi"
>u.baz : string | true
>u : Two
>baz : string | true
>'hi' : "hi"

type Three = { foo: number } | { [s: string]: string } | { [s: string]: boolean };
>Three : { foo: number; } | { [s: string]: string; } | { [s: string]: boolean; }
>foo : number
>s : string
>s : string

declare var v: Three
>v : Three

v.foo = false
>v.foo = false : false
>v.foo : string | number | boolean
>v : Three
>foo : string | number | boolean
>false : false

type Missing = { foo: number, bar: true } | { [s: string]: string } | { foo: boolean }
>Missing : { foo: number; bar: true; } | { [s: string]: string; } | { foo: boolean; }
>foo : number
>bar : true
>true : true
>s : string
>foo : boolean

declare var m: Missing
>m : Missing

m.foo = 'hi'
>m.foo = 'hi' : "hi"
>m.foo : string | number | boolean
>m : Missing
>foo : string | number | boolean
>'hi' : "hi"

m.bar
>m.bar : any
>m : Missing
>bar : any

type RO = { foo: number } | { readonly [s: string]: string }
>RO : { foo: number; } | { readonly [s: string]: string; }
>foo : number
>s : string

declare var ro: RO
>ro : RO

ro.foo = 'not allowed'
>ro.foo = 'not allowed' : "not allowed"
>ro.foo : any
>ro : RO
>foo : any
>'not allowed' : "not allowed"

type Num = { '0': string } | { [n: number]: number }
>Num : { '0': string; } | { [n: number]: number; }
>'0' : string
>n : number

declare var num: Num
>num : Num

num[0] = 1
>num[0] = 1 : 1
>num[0] : string | number
>num : Num
>0 : 0
>1 : 1

num['0'] = 'ok'
>num['0'] = 'ok' : "ok"
>num['0'] : string | number
>num : Num
>'0' : "0"
>'ok' : "ok"

const sym = Symbol()
>sym : unique symbol
>Symbol() : unique symbol
>Symbol : SymbolConstructor

type Both = { s: number, '0': number, [sym]: boolean } | { [n: number]: number, [s: string]: string | number }
>Both : { s: number; '0': number; [sym]: boolean; } | { [n: number]: number; [s: string]: string | number; }
>s : number
>'0' : number
>[sym] : boolean
>sym : unique symbol
>n : number
>s : string

declare var both: Both
>both : Both

both['s'] = 'ok'
>both['s'] = 'ok' : "ok"
>both['s'] : string | number
>both : Both
>'s' : "s"
>'ok' : "ok"

both[0] = 1
>both[0] = 1 : 1
>both[0] : number
>both : Both
>0 : 0
>1 : 1

both[1] = 0 // not ok
>both[1] = 0 : 0
>both[1] : any
>both : Both
>1 : 1
>0 : 0

both[0] = 'not ok'
>both[0] = 'not ok' : "not ok"
>both[0] : number
>both : Both
>0 : 0
>'not ok' : "not ok"

both[sym] = 'not ok'
>both[sym] = 'not ok' : "not ok"
>both[sym] : any
>both : Both
>sym : unique symbol
>'not ok' : "not ok"