|
| 1 | +=== tests/cases/compiler/contextualTypeFunctionObjectPropertyIntersection.ts === |
| 2 | +type Action<TEvent extends { type: string }> = (ev: TEvent) => void; |
| 3 | +>Action : Symbol(Action, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 0, 0)) |
| 4 | +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 0, 12)) |
| 5 | +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 0, 28)) |
| 6 | +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 0, 48)) |
| 7 | +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 0, 12)) |
| 8 | + |
| 9 | +interface MachineConfig<TEvent extends { type: string }> { |
| 10 | +>MachineConfig : Symbol(MachineConfig, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 0, 68)) |
| 11 | +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 2, 24)) |
| 12 | +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 2, 40)) |
| 13 | + |
| 14 | + schema: { |
| 15 | +>schema : Symbol(MachineConfig.schema, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 2, 58)) |
| 16 | + |
| 17 | + events: TEvent; |
| 18 | +>events : Symbol(events, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 3, 11)) |
| 19 | +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 2, 24)) |
| 20 | + |
| 21 | + }; |
| 22 | + on?: { |
| 23 | +>on : Symbol(MachineConfig.on, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 5, 4)) |
| 24 | + |
| 25 | + [K in TEvent["type"]]?: Action<TEvent extends { type: K } ? TEvent : never>; |
| 26 | +>K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 7, 5)) |
| 27 | +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 2, 24)) |
| 28 | +>Action : Symbol(Action, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 0, 0)) |
| 29 | +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 2, 24)) |
| 30 | +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 7, 51)) |
| 31 | +>K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 7, 5)) |
| 32 | +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 2, 24)) |
| 33 | + |
| 34 | + } & { |
| 35 | + "*"?: Action<TEvent>; |
| 36 | +>"*" : Symbol("*", Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 8, 7)) |
| 37 | +>Action : Symbol(Action, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 0, 0)) |
| 38 | +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 2, 24)) |
| 39 | + |
| 40 | + }; |
| 41 | +} |
| 42 | + |
| 43 | +declare function createMachine<TEvent extends { type: string }>( |
| 44 | +>createMachine : Symbol(createMachine, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 11, 1)) |
| 45 | +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 13, 31)) |
| 46 | +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 13, 47)) |
| 47 | + |
| 48 | + config: MachineConfig<TEvent> |
| 49 | +>config : Symbol(config, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 13, 64)) |
| 50 | +>MachineConfig : Symbol(MachineConfig, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 0, 68)) |
| 51 | +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 13, 31)) |
| 52 | + |
| 53 | +): void; |
| 54 | + |
| 55 | +createMachine({ |
| 56 | +>createMachine : Symbol(createMachine, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 11, 1)) |
| 57 | + |
| 58 | + schema: { |
| 59 | +>schema : Symbol(schema, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 17, 15)) |
| 60 | + |
| 61 | + events: {} as { type: "FOO" } | { type: "BAR" }, |
| 62 | +>events : Symbol(events, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 18, 11)) |
| 63 | +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 19, 19)) |
| 64 | +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 19, 37)) |
| 65 | + |
| 66 | + }, |
| 67 | + on: { |
| 68 | +>on : Symbol(on, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 20, 4)) |
| 69 | + |
| 70 | + FOO: (ev) => { |
| 71 | +>FOO : Symbol(FOO, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 21, 7)) |
| 72 | +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 22, 10)) |
| 73 | + |
| 74 | + ev.type; // should be 'FOO' |
| 75 | +>ev.type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 19, 19)) |
| 76 | +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 22, 10)) |
| 77 | +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 19, 19)) |
| 78 | + |
| 79 | + }, |
| 80 | + }, |
| 81 | +}); |
| 82 | + |
0 commit comments