File: neverAsDiscriminantType%28strict%3Dtrue%29.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 (177 lines) | stat: -rw-r--r-- 4,913 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
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
=== tests/cases/compiler/neverAsDiscriminantType.ts ===
type Foo1 = { kind: 'a', a: number } | { kind: 'b' } | { kind: never };
>Foo1 : { kind: 'a'; a: number; } | { kind: 'b'; } | { kind: never; }
>kind : "a"
>a : number
>kind : "b"
>kind : never

function f1(foo: Foo1) {
>f1 : (foo: Foo1) => void
>foo : Foo1

    if (foo.kind === 'a') {
>foo.kind === 'a' : boolean
>foo.kind : "a" | "b"
>foo : Foo1
>kind : "a" | "b"
>'a' : "a"

        foo.a;
>foo.a : number
>foo : { kind: "a"; a: number; }
>a : number
    }
}

type Foo2 = { kind?: 'a', a: number } | { kind?: 'b' } | { kind?: never };
>Foo2 : { kind?: "a" | undefined; a: number; } | { kind?: "b" | undefined; } | { kind?: undefined; }
>kind : "a" | undefined
>a : number
>kind : "b" | undefined
>kind : undefined

function f2(foo: Foo2) {
>f2 : (foo: Foo2) => void
>foo : Foo2

    if (foo.kind === 'a') {
>foo.kind === 'a' : boolean
>foo.kind : "a" | "b" | undefined
>foo : Foo2
>kind : "a" | "b" | undefined
>'a' : "a"

        foo.a;
>foo.a : number
>foo : { kind?: "a" | undefined; a: number; }
>a : number
    }
}

// Repro from #50716

export interface GatewayPayloadStructure<O extends GatewayOpcode, T extends keyof GatewayEvents, D> {
    op: O
>op : O

    d: D
>d : D

    t?: T
>t : T | undefined

    s?: number
>s : number | undefined
}

export type GatewayPayload = {
>GatewayPayload : GatewayPayloadStructure<GatewayOpcode.DISPATCH, "MESSAGE_CREATE", { a: 1; }> | GatewayPayloadStructure<GatewayOpcode.DISPATCH, "MESSAGE_UPDATE", { a: 2; }> | GatewayPayloadStructure<GatewayOpcode.DISPATCH, "MESSAGE_DELETE", { a: 3; }> | GatewayPayloadStructure<GatewayOpcode.HEARTBEAT, never, never> | GatewayPayloadStructure<GatewayOpcode.IDENTIFY, never, never> | GatewayPayloadStructure<GatewayOpcode.PRESENCE_UPDATE, never, never> | GatewayPayloadStructure<GatewayOpcode.VOICE_STATE_UPDATE, never, never> | GatewayPayloadStructure<GatewayOpcode.RESUME, never, never> | GatewayPayloadStructure<GatewayOpcode.RECONNECT, never, never> | GatewayPayloadStructure<GatewayOpcode.REQUEST_GUILD_MEMBERS, never, never> | GatewayPayloadStructure<GatewayOpcode.INVALID_SESSION, never, never> | GatewayPayloadStructure<GatewayOpcode.HELLO, never, { b: 1; }> | GatewayPayloadStructure<GatewayOpcode.HEARTBEAT_ACK, never, never>

    [O in GatewayOpcode]: O extends GatewayOpcode.DISPATCH
>GatewayOpcode : any

    ? {
        [T in keyof GatewayEvents]: GatewayPayloadStructure<GatewayOpcode.DISPATCH, T, GatewayEvents[T]>
>GatewayOpcode : any

    }[keyof GatewayEvents]
    : GatewayPayloadStructure<O, never, O extends keyof GatewayParams ? GatewayParams[O] : never>
}[GatewayOpcode]

export interface GatewayParams {
    [GatewayOpcode.HELLO]: { b: 1 }
>[GatewayOpcode.HELLO] : { b: 1; }
>GatewayOpcode.HELLO : GatewayOpcode.HELLO
>GatewayOpcode : typeof GatewayOpcode
>HELLO : GatewayOpcode.HELLO
>b : 1
}

export enum GatewayOpcode {
>GatewayOpcode : GatewayOpcode

    DISPATCH = 0,
>DISPATCH : GatewayOpcode.DISPATCH
>0 : 0

    HEARTBEAT = 1,
>HEARTBEAT : GatewayOpcode.HEARTBEAT
>1 : 1

    IDENTIFY = 2,
>IDENTIFY : GatewayOpcode.IDENTIFY
>2 : 2

    PRESENCE_UPDATE = 3,
>PRESENCE_UPDATE : GatewayOpcode.PRESENCE_UPDATE
>3 : 3

    VOICE_STATE_UPDATE = 4,
>VOICE_STATE_UPDATE : GatewayOpcode.VOICE_STATE_UPDATE
>4 : 4

    RESUME = 6,
>RESUME : GatewayOpcode.RESUME
>6 : 6

    RECONNECT = 7,
>RECONNECT : GatewayOpcode.RECONNECT
>7 : 7

    REQUEST_GUILD_MEMBERS = 8,
>REQUEST_GUILD_MEMBERS : GatewayOpcode.REQUEST_GUILD_MEMBERS
>8 : 8

    INVALID_SESSION = 9,
>INVALID_SESSION : GatewayOpcode.INVALID_SESSION
>9 : 9

    HELLO = 10,
>HELLO : GatewayOpcode.HELLO
>10 : 10

    HEARTBEAT_ACK = 11,
>HEARTBEAT_ACK : GatewayOpcode.HEARTBEAT_ACK
>11 : 11
}

export interface GatewayEvents {
    MESSAGE_CREATE: { a: 1 }
>MESSAGE_CREATE : { a: 1; }
>a : 1

    MESSAGE_UPDATE: { a: 2 }
>MESSAGE_UPDATE : { a: 2; }
>a : 2

    MESSAGE_DELETE: { a: 3 }
>MESSAGE_DELETE : { a: 3; }
>a : 3
}

function assertMessage(event: { a: 1 }) { }
>assertMessage : (event: {    a: 1;}) => void
>event : { a: 1; }
>a : 1

export async function adaptSession(input: GatewayPayload) {
>adaptSession : (input: GatewayPayload) => Promise<void>
>input : GatewayPayload

    if (input.t === 'MESSAGE_CREATE') {
>input.t === 'MESSAGE_CREATE' : boolean
>input.t : "MESSAGE_CREATE" | "MESSAGE_UPDATE" | "MESSAGE_DELETE" | undefined
>input : GatewayPayload
>t : "MESSAGE_CREATE" | "MESSAGE_UPDATE" | "MESSAGE_DELETE" | undefined
>'MESSAGE_CREATE' : "MESSAGE_CREATE"

        assertMessage(input.d)
>assertMessage(input.d) : void
>assertMessage : (event: { a: 1; }) => void
>input.d : { a: 1; }
>input : GatewayPayloadStructure<GatewayOpcode.DISPATCH, "MESSAGE_CREATE", { a: 1; }>
>d : { a: 1; }
    }
}