|
| 1 | +=== tests/cases/compiler/contextuallyTypedParametersWithInitializers.ts === |
| 2 | +declare function id1<T>(input: T): T; |
| 3 | +>id1 : Symbol(id1, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 0)) |
| 4 | +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 21)) |
| 5 | +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 24)) |
| 6 | +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 21)) |
| 7 | +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 21)) |
| 8 | + |
| 9 | +declare function id2<T extends (x: any) => any>(input: T): T; |
| 10 | +>id2 : Symbol(id2, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 37)) |
| 11 | +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 21)) |
| 12 | +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 32)) |
| 13 | +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 48)) |
| 14 | +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 21)) |
| 15 | +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 21)) |
| 16 | + |
| 17 | +declare function id3<T extends (x: { foo: any }) => any>(input: T): T; |
| 18 | +>id3 : Symbol(id3, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 61)) |
| 19 | +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 21)) |
| 20 | +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 32)) |
| 21 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 36)) |
| 22 | +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 57)) |
| 23 | +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 21)) |
| 24 | +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 21)) |
| 25 | + |
| 26 | +declare function id4<T extends (x: { foo?: number }) => any>(input: T): T; |
| 27 | +>id4 : Symbol(id4, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 70)) |
| 28 | +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 21)) |
| 29 | +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 32)) |
| 30 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 36)) |
| 31 | +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 61)) |
| 32 | +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 21)) |
| 33 | +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 21)) |
| 34 | + |
| 35 | +declare function id5<T extends (x?: number) => any>(input: T): T; |
| 36 | +>id5 : Symbol(id5, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 74)) |
| 37 | +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 4, 21)) |
| 38 | +>x : Symbol(x, Decl(contextuallyTypedParametersWithInitializers.ts, 4, 32)) |
| 39 | +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 4, 52)) |
| 40 | +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 4, 21)) |
| 41 | +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 4, 21)) |
| 42 | + |
| 43 | +const f10 = function ({ foo = 42 }) { return foo }; |
| 44 | +>f10 : Symbol(f10, Decl(contextuallyTypedParametersWithInitializers.ts, 6, 5)) |
| 45 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 6, 23)) |
| 46 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 6, 23)) |
| 47 | + |
| 48 | +const f11 = id1(function ({ foo = 42 }) { return foo }); // Implicit any error |
| 49 | +>f11 : Symbol(f11, Decl(contextuallyTypedParametersWithInitializers.ts, 7, 5)) |
| 50 | +>id1 : Symbol(id1, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 0)) |
| 51 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 7, 27)) |
| 52 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 7, 27)) |
| 53 | + |
| 54 | +const f12 = id2(function ({ foo = 42 }) { return foo }); |
| 55 | +>f12 : Symbol(f12, Decl(contextuallyTypedParametersWithInitializers.ts, 8, 5)) |
| 56 | +>id2 : Symbol(id2, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 37)) |
| 57 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 8, 27)) |
| 58 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 8, 27)) |
| 59 | + |
| 60 | +const f13 = id3(function ({ foo = 42 }) { return foo }); |
| 61 | +>f13 : Symbol(f13, Decl(contextuallyTypedParametersWithInitializers.ts, 9, 5)) |
| 62 | +>id3 : Symbol(id3, Decl(contextuallyTypedParametersWithInitializers.ts, 1, 61)) |
| 63 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 9, 27)) |
| 64 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 9, 27)) |
| 65 | + |
| 66 | +const f14 = id4(function ({ foo = 42 }) { return foo }); |
| 67 | +>f14 : Symbol(f14, Decl(contextuallyTypedParametersWithInitializers.ts, 10, 5)) |
| 68 | +>id4 : Symbol(id4, Decl(contextuallyTypedParametersWithInitializers.ts, 2, 70)) |
| 69 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 10, 27)) |
| 70 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 10, 27)) |
| 71 | + |
| 72 | +const f20 = function (foo = 42) { return foo }; |
| 73 | +>f20 : Symbol(f20, Decl(contextuallyTypedParametersWithInitializers.ts, 12, 5)) |
| 74 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 12, 22)) |
| 75 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 12, 22)) |
| 76 | + |
| 77 | +const f21 = id1(function (foo = 42) { return foo }); // Implicit any error |
| 78 | +>f21 : Symbol(f21, Decl(contextuallyTypedParametersWithInitializers.ts, 13, 5)) |
| 79 | +>id1 : Symbol(id1, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 0)) |
| 80 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 13, 26)) |
| 81 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 13, 26)) |
| 82 | + |
| 83 | +const f22 = id2(function (foo = 42) { return foo }); |
| 84 | +>f22 : Symbol(f22, Decl(contextuallyTypedParametersWithInitializers.ts, 14, 5)) |
| 85 | +>id2 : Symbol(id2, Decl(contextuallyTypedParametersWithInitializers.ts, 0, 37)) |
| 86 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 14, 26)) |
| 87 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 14, 26)) |
| 88 | + |
| 89 | +const f25 = id5(function (foo = 42) { return foo }); |
| 90 | +>f25 : Symbol(f25, Decl(contextuallyTypedParametersWithInitializers.ts, 15, 5)) |
| 91 | +>id5 : Symbol(id5, Decl(contextuallyTypedParametersWithInitializers.ts, 3, 74)) |
| 92 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 15, 26)) |
| 93 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 15, 26)) |
| 94 | + |
| 95 | +// Repro from #28816 |
| 96 | + |
| 97 | +function id<T>(input: T): T { return input } |
| 98 | +>id : Symbol(id, Decl(contextuallyTypedParametersWithInitializers.ts, 15, 52)) |
| 99 | +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 19, 12)) |
| 100 | +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 19, 15)) |
| 101 | +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 19, 12)) |
| 102 | +>T : Symbol(T, Decl(contextuallyTypedParametersWithInitializers.ts, 19, 12)) |
| 103 | +>input : Symbol(input, Decl(contextuallyTypedParametersWithInitializers.ts, 19, 15)) |
| 104 | + |
| 105 | +function getFoo ({ foo = 42 }) { |
| 106 | +>getFoo : Symbol(getFoo, Decl(contextuallyTypedParametersWithInitializers.ts, 19, 44)) |
| 107 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 21, 18)) |
| 108 | + |
| 109 | + return foo; |
| 110 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 21, 18)) |
| 111 | +} |
| 112 | + |
| 113 | +const newGetFoo = id(getFoo); |
| 114 | +>newGetFoo : Symbol(newGetFoo, Decl(contextuallyTypedParametersWithInitializers.ts, 25, 5)) |
| 115 | +>id : Symbol(id, Decl(contextuallyTypedParametersWithInitializers.ts, 15, 52)) |
| 116 | +>getFoo : Symbol(getFoo, Decl(contextuallyTypedParametersWithInitializers.ts, 19, 44)) |
| 117 | + |
| 118 | +const newGetFoo2 = id(function getFoo ({ foo = 42 }) { |
| 119 | +>newGetFoo2 : Symbol(newGetFoo2, Decl(contextuallyTypedParametersWithInitializers.ts, 26, 5)) |
| 120 | +>id : Symbol(id, Decl(contextuallyTypedParametersWithInitializers.ts, 15, 52)) |
| 121 | +>getFoo : Symbol(getFoo, Decl(contextuallyTypedParametersWithInitializers.ts, 26, 22)) |
| 122 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 26, 40)) |
| 123 | + |
| 124 | + return foo; |
| 125 | +>foo : Symbol(foo, Decl(contextuallyTypedParametersWithInitializers.ts, 26, 40)) |
| 126 | + |
| 127 | +}); |
| 128 | + |
0 commit comments