|
| 1 | +//// [tests/cases/conformance/types/typeRelationships/typeInference/noInferVsDistributiveConditionalType2.ts] //// |
| 2 | + |
| 3 | +=== noInferVsDistributiveConditionalType2.ts === |
| 4 | +type EventObject = { |
| 5 | +>EventObject : Symbol(EventObject, Decl(noInferVsDistributiveConditionalType2.ts, 0, 0)) |
| 6 | + |
| 7 | + type: string; |
| 8 | +>type : Symbol(type, Decl(noInferVsDistributiveConditionalType2.ts, 0, 20)) |
| 9 | + |
| 10 | +}; |
| 11 | + |
| 12 | +type FooEvent = { type: "FOO" }; |
| 13 | +>FooEvent : Symbol(FooEvent, Decl(noInferVsDistributiveConditionalType2.ts, 2, 2)) |
| 14 | +>type : Symbol(type, Decl(noInferVsDistributiveConditionalType2.ts, 4, 17)) |
| 15 | + |
| 16 | +type BarEvent = { type: "BAR" }; |
| 17 | +>BarEvent : Symbol(BarEvent, Decl(noInferVsDistributiveConditionalType2.ts, 4, 32)) |
| 18 | +>type : Symbol(type, Decl(noInferVsDistributiveConditionalType2.ts, 5, 17)) |
| 19 | + |
| 20 | +type Input = FooEvent | BarEvent; |
| 21 | +>Input : Symbol(Input, Decl(noInferVsDistributiveConditionalType2.ts, 5, 32)) |
| 22 | +>FooEvent : Symbol(FooEvent, Decl(noInferVsDistributiveConditionalType2.ts, 2, 2)) |
| 23 | +>BarEvent : Symbol(BarEvent, Decl(noInferVsDistributiveConditionalType2.ts, 4, 32)) |
| 24 | + |
| 25 | +type ExtractEventSimplified< |
| 26 | +>ExtractEventSimplified : Symbol(ExtractEventSimplified, Decl(noInferVsDistributiveConditionalType2.ts, 7, 33)) |
| 27 | + |
| 28 | + TEvent extends EventObject, |
| 29 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 9, 28)) |
| 30 | +>EventObject : Symbol(EventObject, Decl(noInferVsDistributiveConditionalType2.ts, 0, 0)) |
| 31 | + |
| 32 | + K extends TEvent["type"], |
| 33 | +>K : Symbol(K, Decl(noInferVsDistributiveConditionalType2.ts, 10, 29)) |
| 34 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 9, 28)) |
| 35 | + |
| 36 | +> = string extends TEvent["type"] ? TEvent : Extract<TEvent, { type: K }>; |
| 37 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 9, 28)) |
| 38 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 9, 28)) |
| 39 | +>Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --)) |
| 40 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 9, 28)) |
| 41 | +>type : Symbol(type, Decl(noInferVsDistributiveConditionalType2.ts, 12, 62)) |
| 42 | +>K : Symbol(K, Decl(noInferVsDistributiveConditionalType2.ts, 10, 29)) |
| 43 | + |
| 44 | +type Result = ExtractEventSimplified<NoInfer<Input>, "FOO">; |
| 45 | +>Result : Symbol(Result, Decl(noInferVsDistributiveConditionalType2.ts, 12, 74)) |
| 46 | +>ExtractEventSimplified : Symbol(ExtractEventSimplified, Decl(noInferVsDistributiveConditionalType2.ts, 7, 33)) |
| 47 | +>NoInfer : Symbol(NoInfer, Decl(lib.es5.d.ts, --, --)) |
| 48 | +>Input : Symbol(Input, Decl(noInferVsDistributiveConditionalType2.ts, 5, 32)) |
| 49 | + |
| 50 | +type EventDescriptorMatches< |
| 51 | +>EventDescriptorMatches : Symbol(EventDescriptorMatches, Decl(noInferVsDistributiveConditionalType2.ts, 14, 60)) |
| 52 | + |
| 53 | + TEventType extends string, |
| 54 | +>TEventType : Symbol(TEventType, Decl(noInferVsDistributiveConditionalType2.ts, 16, 28)) |
| 55 | + |
| 56 | + TNormalizedDescriptor, |
| 57 | +>TNormalizedDescriptor : Symbol(TNormalizedDescriptor, Decl(noInferVsDistributiveConditionalType2.ts, 17, 28)) |
| 58 | + |
| 59 | +> = TEventType extends TNormalizedDescriptor ? true : false; |
| 60 | +>TEventType : Symbol(TEventType, Decl(noInferVsDistributiveConditionalType2.ts, 16, 28)) |
| 61 | +>TNormalizedDescriptor : Symbol(TNormalizedDescriptor, Decl(noInferVsDistributiveConditionalType2.ts, 17, 28)) |
| 62 | + |
| 63 | +type PartialEventDescriptor<TEventType extends string> = |
| 64 | +>PartialEventDescriptor : Symbol(PartialEventDescriptor, Decl(noInferVsDistributiveConditionalType2.ts, 19, 60)) |
| 65 | +>TEventType : Symbol(TEventType, Decl(noInferVsDistributiveConditionalType2.ts, 21, 28)) |
| 66 | + |
| 67 | + TEventType extends `${infer TLeading}.${infer TTail}` |
| 68 | +>TEventType : Symbol(TEventType, Decl(noInferVsDistributiveConditionalType2.ts, 21, 28)) |
| 69 | +>TLeading : Symbol(TLeading, Decl(noInferVsDistributiveConditionalType2.ts, 22, 29)) |
| 70 | +>TTail : Symbol(TTail, Decl(noInferVsDistributiveConditionalType2.ts, 22, 47)) |
| 71 | + |
| 72 | + ? `${TLeading}.*` | `${TLeading}.${PartialEventDescriptor<TTail>}` |
| 73 | +>TLeading : Symbol(TLeading, Decl(noInferVsDistributiveConditionalType2.ts, 22, 29)) |
| 74 | +>TLeading : Symbol(TLeading, Decl(noInferVsDistributiveConditionalType2.ts, 22, 29)) |
| 75 | +>PartialEventDescriptor : Symbol(PartialEventDescriptor, Decl(noInferVsDistributiveConditionalType2.ts, 19, 60)) |
| 76 | +>TTail : Symbol(TTail, Decl(noInferVsDistributiveConditionalType2.ts, 22, 47)) |
| 77 | + |
| 78 | + : never; |
| 79 | + |
| 80 | +type EventDescriptor<TEvent extends EventObject> = |
| 81 | +>EventDescriptor : Symbol(EventDescriptor, Decl(noInferVsDistributiveConditionalType2.ts, 24, 12)) |
| 82 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 26, 21)) |
| 83 | +>EventObject : Symbol(EventObject, Decl(noInferVsDistributiveConditionalType2.ts, 0, 0)) |
| 84 | + |
| 85 | + | TEvent["type"] |
| 86 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 26, 21)) |
| 87 | + |
| 88 | + | PartialEventDescriptor<TEvent["type"]> |
| 89 | +>PartialEventDescriptor : Symbol(PartialEventDescriptor, Decl(noInferVsDistributiveConditionalType2.ts, 19, 60)) |
| 90 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 26, 21)) |
| 91 | + |
| 92 | + | "*"; |
| 93 | + |
| 94 | +type NormalizeDescriptor<TDescriptor extends string> = TDescriptor extends "*" |
| 95 | +>NormalizeDescriptor : Symbol(NormalizeDescriptor, Decl(noInferVsDistributiveConditionalType2.ts, 29, 8)) |
| 96 | +>TDescriptor : Symbol(TDescriptor, Decl(noInferVsDistributiveConditionalType2.ts, 31, 25)) |
| 97 | +>TDescriptor : Symbol(TDescriptor, Decl(noInferVsDistributiveConditionalType2.ts, 31, 25)) |
| 98 | + |
| 99 | + ? string |
| 100 | + : TDescriptor extends `${infer TLeading}.*` |
| 101 | +>TDescriptor : Symbol(TDescriptor, Decl(noInferVsDistributiveConditionalType2.ts, 31, 25)) |
| 102 | +>TLeading : Symbol(TLeading, Decl(noInferVsDistributiveConditionalType2.ts, 33, 32)) |
| 103 | + |
| 104 | + ? `${TLeading}.${string}` |
| 105 | +>TLeading : Symbol(TLeading, Decl(noInferVsDistributiveConditionalType2.ts, 33, 32)) |
| 106 | + |
| 107 | + : TDescriptor; |
| 108 | +>TDescriptor : Symbol(TDescriptor, Decl(noInferVsDistributiveConditionalType2.ts, 31, 25)) |
| 109 | + |
| 110 | +type ExtractEvent< |
| 111 | +>ExtractEvent : Symbol(ExtractEvent, Decl(noInferVsDistributiveConditionalType2.ts, 35, 16)) |
| 112 | + |
| 113 | + TEvent extends EventObject, |
| 114 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 37, 18)) |
| 115 | +>EventObject : Symbol(EventObject, Decl(noInferVsDistributiveConditionalType2.ts, 0, 0)) |
| 116 | + |
| 117 | + TDescriptor extends EventDescriptor<TEvent>, |
| 118 | +>TDescriptor : Symbol(TDescriptor, Decl(noInferVsDistributiveConditionalType2.ts, 38, 29)) |
| 119 | +>EventDescriptor : Symbol(EventDescriptor, Decl(noInferVsDistributiveConditionalType2.ts, 24, 12)) |
| 120 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 37, 18)) |
| 121 | + |
| 122 | +> = string extends TEvent["type"] |
| 123 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 37, 18)) |
| 124 | + |
| 125 | + ? TEvent |
| 126 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 37, 18)) |
| 127 | + |
| 128 | + : NormalizeDescriptor<TDescriptor> extends infer TNormalizedDescriptor |
| 129 | +>NormalizeDescriptor : Symbol(NormalizeDescriptor, Decl(noInferVsDistributiveConditionalType2.ts, 29, 8)) |
| 130 | +>TDescriptor : Symbol(TDescriptor, Decl(noInferVsDistributiveConditionalType2.ts, 38, 29)) |
| 131 | +>TNormalizedDescriptor : Symbol(TNormalizedDescriptor, Decl(noInferVsDistributiveConditionalType2.ts, 42, 50)) |
| 132 | + |
| 133 | + ? TEvent extends any |
| 134 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 37, 18)) |
| 135 | + |
| 136 | + ? // true is the check type here to match both true and boolean |
| 137 | + true extends EventDescriptorMatches<TEvent["type"], TNormalizedDescriptor> |
| 138 | +>EventDescriptorMatches : Symbol(EventDescriptorMatches, Decl(noInferVsDistributiveConditionalType2.ts, 14, 60)) |
| 139 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 37, 18)) |
| 140 | +>TNormalizedDescriptor : Symbol(TNormalizedDescriptor, Decl(noInferVsDistributiveConditionalType2.ts, 42, 50)) |
| 141 | + |
| 142 | + ? TEvent |
| 143 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 37, 18)) |
| 144 | + |
| 145 | + : never |
| 146 | + : never |
| 147 | + : never; |
| 148 | + |
| 149 | +type ActionFunction< |
| 150 | +>ActionFunction : Symbol(ActionFunction, Decl(noInferVsDistributiveConditionalType2.ts, 49, 10)) |
| 151 | + |
| 152 | + TExpressionEvent extends EventObject, |
| 153 | +>TExpressionEvent : Symbol(TExpressionEvent, Decl(noInferVsDistributiveConditionalType2.ts, 51, 20)) |
| 154 | +>EventObject : Symbol(EventObject, Decl(noInferVsDistributiveConditionalType2.ts, 0, 0)) |
| 155 | + |
| 156 | + TEvent extends EventObject, |
| 157 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 52, 39)) |
| 158 | +>EventObject : Symbol(EventObject, Decl(noInferVsDistributiveConditionalType2.ts, 0, 0)) |
| 159 | + |
| 160 | +> = { |
| 161 | + (args: { event: TExpressionEvent }): void; |
| 162 | +>args : Symbol(args, Decl(noInferVsDistributiveConditionalType2.ts, 55, 3)) |
| 163 | +>event : Symbol(event, Decl(noInferVsDistributiveConditionalType2.ts, 55, 10)) |
| 164 | +>TExpressionEvent : Symbol(TExpressionEvent, Decl(noInferVsDistributiveConditionalType2.ts, 51, 20)) |
| 165 | + |
| 166 | + _out_TEvent?: TEvent; |
| 167 | +>_out_TEvent : Symbol(_out_TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 55, 44)) |
| 168 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 52, 39)) |
| 169 | + |
| 170 | +}; |
| 171 | + |
| 172 | +type TransitionsConfig<TEvent extends EventObject> = { |
| 173 | +>TransitionsConfig : Symbol(TransitionsConfig, Decl(noInferVsDistributiveConditionalType2.ts, 57, 2)) |
| 174 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 59, 23)) |
| 175 | +>EventObject : Symbol(EventObject, Decl(noInferVsDistributiveConditionalType2.ts, 0, 0)) |
| 176 | + |
| 177 | + [K in EventDescriptor<TEvent>]?: { |
| 178 | +>K : Symbol(K, Decl(noInferVsDistributiveConditionalType2.ts, 60, 3)) |
| 179 | +>EventDescriptor : Symbol(EventDescriptor, Decl(noInferVsDistributiveConditionalType2.ts, 24, 12)) |
| 180 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 59, 23)) |
| 181 | + |
| 182 | + actions?: ActionFunction<ExtractEvent<TEvent, K>, TEvent>; |
| 183 | +>actions : Symbol(actions, Decl(noInferVsDistributiveConditionalType2.ts, 60, 36)) |
| 184 | +>ActionFunction : Symbol(ActionFunction, Decl(noInferVsDistributiveConditionalType2.ts, 49, 10)) |
| 185 | +>ExtractEvent : Symbol(ExtractEvent, Decl(noInferVsDistributiveConditionalType2.ts, 35, 16)) |
| 186 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 59, 23)) |
| 187 | +>K : Symbol(K, Decl(noInferVsDistributiveConditionalType2.ts, 60, 3)) |
| 188 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 59, 23)) |
| 189 | + |
| 190 | + }; |
| 191 | +}; |
| 192 | + |
| 193 | +declare function createMachine<TEvent extends EventObject>(config: { |
| 194 | +>createMachine : Symbol(createMachine, Decl(noInferVsDistributiveConditionalType2.ts, 63, 2)) |
| 195 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 65, 31)) |
| 196 | +>EventObject : Symbol(EventObject, Decl(noInferVsDistributiveConditionalType2.ts, 0, 0)) |
| 197 | +>config : Symbol(config, Decl(noInferVsDistributiveConditionalType2.ts, 65, 59)) |
| 198 | + |
| 199 | + types?: { |
| 200 | +>types : Symbol(types, Decl(noInferVsDistributiveConditionalType2.ts, 65, 68)) |
| 201 | + |
| 202 | + events?: TEvent; |
| 203 | +>events : Symbol(events, Decl(noInferVsDistributiveConditionalType2.ts, 66, 11)) |
| 204 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 65, 31)) |
| 205 | + |
| 206 | + }; |
| 207 | + on?: TransitionsConfig<NoInfer<TEvent>>; |
| 208 | +>on : Symbol(on, Decl(noInferVsDistributiveConditionalType2.ts, 68, 4)) |
| 209 | +>TransitionsConfig : Symbol(TransitionsConfig, Decl(noInferVsDistributiveConditionalType2.ts, 57, 2)) |
| 210 | +>NoInfer : Symbol(NoInfer, Decl(lib.es5.d.ts, --, --)) |
| 211 | +>TEvent : Symbol(TEvent, Decl(noInferVsDistributiveConditionalType2.ts, 65, 31)) |
| 212 | + |
| 213 | +}): void; |
| 214 | + |
| 215 | +createMachine({ |
| 216 | +>createMachine : Symbol(createMachine, Decl(noInferVsDistributiveConditionalType2.ts, 63, 2)) |
| 217 | + |
| 218 | + types: { |
| 219 | +>types : Symbol(types, Decl(noInferVsDistributiveConditionalType2.ts, 72, 15)) |
| 220 | + |
| 221 | + events: {} as { type: "FOO" } | { type: "BAR" }, |
| 222 | +>events : Symbol(events, Decl(noInferVsDistributiveConditionalType2.ts, 73, 10)) |
| 223 | +>type : Symbol(type, Decl(noInferVsDistributiveConditionalType2.ts, 74, 19)) |
| 224 | +>type : Symbol(type, Decl(noInferVsDistributiveConditionalType2.ts, 74, 37)) |
| 225 | + |
| 226 | + }, |
| 227 | + on: { |
| 228 | +>on : Symbol(on, Decl(noInferVsDistributiveConditionalType2.ts, 75, 4)) |
| 229 | + |
| 230 | + FOO: { |
| 231 | +>FOO : Symbol(FOO, Decl(noInferVsDistributiveConditionalType2.ts, 76, 7)) |
| 232 | + |
| 233 | + actions: ({ event }) => { |
| 234 | +>actions : Symbol(actions, Decl(noInferVsDistributiveConditionalType2.ts, 77, 10)) |
| 235 | +>event : Symbol(event, Decl(noInferVsDistributiveConditionalType2.ts, 78, 17)) |
| 236 | + |
| 237 | + event; // { type: "FOO"; } |
| 238 | +>event : Symbol(event, Decl(noInferVsDistributiveConditionalType2.ts, 78, 17)) |
| 239 | + |
| 240 | + }, |
| 241 | + }, |
| 242 | + }, |
| 243 | +}); |
| 244 | + |
0 commit comments