|
| 1 | +=== tests/cases/compiler/coAndContraVariantInferences.ts === |
| 2 | +type A = { kind: 'a' }; |
| 3 | +>A : Symbol(A, Decl(coAndContraVariantInferences.ts, 0, 0)) |
| 4 | +>kind : Symbol(kind, Decl(coAndContraVariantInferences.ts, 0, 10)) |
| 5 | + |
| 6 | +type B = { kind: 'b' }; |
| 7 | +>B : Symbol(B, Decl(coAndContraVariantInferences.ts, 0, 23)) |
| 8 | +>kind : Symbol(kind, Decl(coAndContraVariantInferences.ts, 1, 10)) |
| 9 | + |
| 10 | +declare const a: A; |
| 11 | +>a : Symbol(a, Decl(coAndContraVariantInferences.ts, 3, 13)) |
| 12 | +>A : Symbol(A, Decl(coAndContraVariantInferences.ts, 0, 0)) |
| 13 | + |
| 14 | +declare const b: B; |
| 15 | +>b : Symbol(b, Decl(coAndContraVariantInferences.ts, 4, 13)) |
| 16 | +>B : Symbol(B, Decl(coAndContraVariantInferences.ts, 0, 23)) |
| 17 | + |
| 18 | +declare function fab(arg: A | B): void; |
| 19 | +>fab : Symbol(fab, Decl(coAndContraVariantInferences.ts, 4, 19)) |
| 20 | +>arg : Symbol(arg, Decl(coAndContraVariantInferences.ts, 6, 21)) |
| 21 | +>A : Symbol(A, Decl(coAndContraVariantInferences.ts, 0, 0)) |
| 22 | +>B : Symbol(B, Decl(coAndContraVariantInferences.ts, 0, 23)) |
| 23 | + |
| 24 | +declare function foo<T>(x: { kind: T }, f: (arg: { kind: T }) => void): void; |
| 25 | +>foo : Symbol(foo, Decl(coAndContraVariantInferences.ts, 6, 39)) |
| 26 | +>T : Symbol(T, Decl(coAndContraVariantInferences.ts, 8, 21)) |
| 27 | +>x : Symbol(x, Decl(coAndContraVariantInferences.ts, 8, 24)) |
| 28 | +>kind : Symbol(kind, Decl(coAndContraVariantInferences.ts, 8, 28)) |
| 29 | +>T : Symbol(T, Decl(coAndContraVariantInferences.ts, 8, 21)) |
| 30 | +>f : Symbol(f, Decl(coAndContraVariantInferences.ts, 8, 39)) |
| 31 | +>arg : Symbol(arg, Decl(coAndContraVariantInferences.ts, 8, 44)) |
| 32 | +>kind : Symbol(kind, Decl(coAndContraVariantInferences.ts, 8, 50)) |
| 33 | +>T : Symbol(T, Decl(coAndContraVariantInferences.ts, 8, 21)) |
| 34 | + |
| 35 | +foo(a, fab); |
| 36 | +>foo : Symbol(foo, Decl(coAndContraVariantInferences.ts, 6, 39)) |
| 37 | +>a : Symbol(a, Decl(coAndContraVariantInferences.ts, 3, 13)) |
| 38 | +>fab : Symbol(fab, Decl(coAndContraVariantInferences.ts, 4, 19)) |
| 39 | + |
| 40 | +foo(b, fab); |
| 41 | +>foo : Symbol(foo, Decl(coAndContraVariantInferences.ts, 6, 39)) |
| 42 | +>b : Symbol(b, Decl(coAndContraVariantInferences.ts, 4, 13)) |
| 43 | +>fab : Symbol(fab, Decl(coAndContraVariantInferences.ts, 4, 19)) |
| 44 | + |
| 45 | +// Repro from #45603 |
| 46 | + |
| 47 | +interface Action<TName extends string,TPayload> { |
| 48 | +>Action : Symbol(Action, Decl(coAndContraVariantInferences.ts, 11, 12)) |
| 49 | +>TName : Symbol(TName, Decl(coAndContraVariantInferences.ts, 15, 17)) |
| 50 | +>TPayload : Symbol(TPayload, Decl(coAndContraVariantInferences.ts, 15, 38)) |
| 51 | + |
| 52 | + name: TName, |
| 53 | +>name : Symbol(Action.name, Decl(coAndContraVariantInferences.ts, 15, 49)) |
| 54 | +>TName : Symbol(TName, Decl(coAndContraVariantInferences.ts, 15, 17)) |
| 55 | + |
| 56 | + payload: TPayload |
| 57 | +>payload : Symbol(Action.payload, Decl(coAndContraVariantInferences.ts, 16, 16)) |
| 58 | +>TPayload : Symbol(TPayload, Decl(coAndContraVariantInferences.ts, 15, 38)) |
| 59 | +} |
| 60 | + |
| 61 | +const actionA = { payload: 'any-string' } as Action<'ACTION_A', string>; |
| 62 | +>actionA : Symbol(actionA, Decl(coAndContraVariantInferences.ts, 20, 5)) |
| 63 | +>payload : Symbol(payload, Decl(coAndContraVariantInferences.ts, 20, 17)) |
| 64 | +>Action : Symbol(Action, Decl(coAndContraVariantInferences.ts, 11, 12)) |
| 65 | + |
| 66 | +const actionB = { payload: true } as Action<'ACTION_B', boolean>; |
| 67 | +>actionB : Symbol(actionB, Decl(coAndContraVariantInferences.ts, 21, 5)) |
| 68 | +>payload : Symbol(payload, Decl(coAndContraVariantInferences.ts, 21, 17)) |
| 69 | +>Action : Symbol(Action, Decl(coAndContraVariantInferences.ts, 11, 12)) |
| 70 | + |
| 71 | +function call<TName extends string,TPayload>( |
| 72 | +>call : Symbol(call, Decl(coAndContraVariantInferences.ts, 21, 65)) |
| 73 | +>TName : Symbol(TName, Decl(coAndContraVariantInferences.ts, 23, 14)) |
| 74 | +>TPayload : Symbol(TPayload, Decl(coAndContraVariantInferences.ts, 23, 35)) |
| 75 | + |
| 76 | + action: Action<TName,TPayload>, |
| 77 | +>action : Symbol(action, Decl(coAndContraVariantInferences.ts, 23, 45)) |
| 78 | +>Action : Symbol(Action, Decl(coAndContraVariantInferences.ts, 11, 12)) |
| 79 | +>TName : Symbol(TName, Decl(coAndContraVariantInferences.ts, 23, 14)) |
| 80 | +>TPayload : Symbol(TPayload, Decl(coAndContraVariantInferences.ts, 23, 35)) |
| 81 | + |
| 82 | + fn: (action: Action<TName,TPayload>)=> any, |
| 83 | +>fn : Symbol(fn, Decl(coAndContraVariantInferences.ts, 24, 33)) |
| 84 | +>action : Symbol(action, Decl(coAndContraVariantInferences.ts, 25, 7)) |
| 85 | +>Action : Symbol(Action, Decl(coAndContraVariantInferences.ts, 11, 12)) |
| 86 | +>TName : Symbol(TName, Decl(coAndContraVariantInferences.ts, 23, 14)) |
| 87 | +>TPayload : Symbol(TPayload, Decl(coAndContraVariantInferences.ts, 23, 35)) |
| 88 | + |
| 89 | +) { |
| 90 | + fn(action); |
| 91 | +>fn : Symbol(fn, Decl(coAndContraVariantInferences.ts, 24, 33)) |
| 92 | +>action : Symbol(action, Decl(coAndContraVariantInferences.ts, 23, 45)) |
| 93 | +} |
| 94 | + |
| 95 | +const printFn = (action: typeof actionA | typeof actionB)=> console.log(action); |
| 96 | +>printFn : Symbol(printFn, Decl(coAndContraVariantInferences.ts, 30, 5)) |
| 97 | +>action : Symbol(action, Decl(coAndContraVariantInferences.ts, 30, 17)) |
| 98 | +>actionA : Symbol(actionA, Decl(coAndContraVariantInferences.ts, 20, 5)) |
| 99 | +>actionB : Symbol(actionB, Decl(coAndContraVariantInferences.ts, 21, 5)) |
| 100 | +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 101 | +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) |
| 102 | +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) |
| 103 | +>action : Symbol(action, Decl(coAndContraVariantInferences.ts, 30, 17)) |
| 104 | + |
| 105 | +call(actionA, printFn); |
| 106 | +>call : Symbol(call, Decl(coAndContraVariantInferences.ts, 21, 65)) |
| 107 | +>actionA : Symbol(actionA, Decl(coAndContraVariantInferences.ts, 20, 5)) |
| 108 | +>printFn : Symbol(printFn, Decl(coAndContraVariantInferences.ts, 30, 5)) |
| 109 | + |
| 110 | +call(actionB, printFn); |
| 111 | +>call : Symbol(call, Decl(coAndContraVariantInferences.ts, 21, 65)) |
| 112 | +>actionB : Symbol(actionB, Decl(coAndContraVariantInferences.ts, 21, 5)) |
| 113 | +>printFn : Symbol(printFn, Decl(coAndContraVariantInferences.ts, 30, 5)) |
| 114 | + |
0 commit comments