File: literalTypes1.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 (198 lines) | stat: -rw-r--r-- 2,679 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
=== tests/cases/conformance/types/literal/literalTypes1.ts ===
let zero: 0 = 0;
>zero : 0
>0 : 0

let one: 1 = 1;
>one : 1
>1 : 1

let two: 2 = 2;
>two : 2
>2 : 2

let oneOrTwo: 1 | 2 = <1 | 2>1;
>oneOrTwo : 1 | 2
><1 | 2>1 : 1 | 2
>1 : 1

function f1(x: 0 | 1 | 2) {
>f1 : (x: 0 | 1 | 2) => void
>x : 0 | 1 | 2

    switch (x) {
>x : 0 | 1 | 2

        case zero:
>zero : 0

            x;
>x : 0

            break;
        case one:
>one : 1

            x;
>x : 1

            break;
        case two:
>two : 2

            x;
>x : 2

            break;
        default:
            x;
>x : never
    }
}

function f2(x: 0 | 1 | 2) {
>f2 : (x: 0 | 1 | 2) => void
>x : 0 | 1 | 2

    switch (x) {
>x : 0 | 1 | 2

        case zero:
>zero : 0

            x;
>x : 0

            break;
        case oneOrTwo:
>oneOrTwo : 1 | 2

            x;
>x : 1 | 2

            break;
        default:
            x;
>x : 1 | 2
    }
}

type Falsy = false | 0 | "" | null | undefined;
>Falsy : false | "" | 0 | null | undefined
>false : false
>null : null

function f3(x: Falsy) {
>f3 : (x: Falsy) => void
>x : Falsy

    if (x) {
>x : Falsy

        x;
>x : never
    }
    else {
        x;
>x : Falsy
    }
}

function f4(x: 0 | 1 | true | string) {
>f4 : (x: 0 | 1 | true | string) => void
>x : string | true | 0 | 1
>true : true

    switch (x) {
>x : string | true | 0 | 1

        case 0:
>0 : 0

            x;
>x : 0

            break;
        case 1:
>1 : 1

            x;
>x : 1

            break;
        case "abc":
>"abc" : "abc"

        case "def":
>"def" : "def"

            x;
>x : "abc" | "def"

            break;
        case null:
>null : null

            x;
>x : never

            break;
        case undefined:
>undefined : undefined

            x;
>x : never

            break;
        default:
            x;
>x : string | true
    }
}

function f5(x: string | number | boolean) {
>f5 : (x: string | number | boolean) => void
>x : string | number | boolean

    switch (x) {
>x : string | number | boolean

        case "abc":
>"abc" : "abc"

            x;
>x : "abc"

            break;
        case 0:
>0 : 0

        case 1:
>1 : 1

            x;
>x : 0 | 1

            break;
        case true:
>true : true

            x;
>x : true

            break;
        case "hello":
>"hello" : "hello"

        case 123:
>123 : 123

            x;
>x : "hello" | 123

            break;
        default:
            x;
>x : string | number | false
    }
}