• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// @strict: true, false
2
3type Foo1 = { kind: 'a', a: number } | { kind: 'b' } | { kind: never };
4
5function f1(foo: Foo1) {
6    if (foo.kind === 'a') {
7        foo.a;
8    }
9}
10
11type Foo2 = { kind?: 'a', a: number } | { kind?: 'b' } | { kind?: never };
12
13function f2(foo: Foo2) {
14    if (foo.kind === 'a') {
15        foo.a;
16    }
17}
18
19// Repro from #50716
20
21export interface GatewayPayloadStructure<O extends GatewayOpcode, T extends keyof GatewayEvents, D> {
22    op: O
23    d: D
24    t?: T
25    s?: number
26}
27
28export type GatewayPayload = {
29    [O in GatewayOpcode]: O extends GatewayOpcode.DISPATCH
30    ? {
31        [T in keyof GatewayEvents]: GatewayPayloadStructure<GatewayOpcode.DISPATCH, T, GatewayEvents[T]>
32    }[keyof GatewayEvents]
33    : GatewayPayloadStructure<O, never, O extends keyof GatewayParams ? GatewayParams[O] : never>
34}[GatewayOpcode]
35
36export interface GatewayParams {
37    [GatewayOpcode.HELLO]: { b: 1 }
38}
39
40export enum GatewayOpcode {
41    DISPATCH = 0,
42    HEARTBEAT = 1,
43    IDENTIFY = 2,
44    PRESENCE_UPDATE = 3,
45    VOICE_STATE_UPDATE = 4,
46    RESUME = 6,
47    RECONNECT = 7,
48    REQUEST_GUILD_MEMBERS = 8,
49    INVALID_SESSION = 9,
50    HELLO = 10,
51    HEARTBEAT_ACK = 11,
52}
53
54export interface GatewayEvents {
55    MESSAGE_CREATE: { a: 1 }
56    MESSAGE_UPDATE: { a: 2 }
57    MESSAGE_DELETE: { a: 3 }
58}
59
60function assertMessage(event: { a: 1 }) { }
61
62export async function adaptSession(input: GatewayPayload) {
63    if (input.t === 'MESSAGE_CREATE') {
64        assertMessage(input.d)
65    }
66}
67