|
| 1 | +=== tests/cases/compiler/contextualTypeInObjectProperty.ts === |
| 2 | +type Shape = { |
| 3 | +>Shape : Symbol(Shape, Decl(contextualTypeInObjectProperty.ts, 0, 0)) |
| 4 | + |
| 5 | + "a"?: (a: "a") => "a"; |
| 6 | +>"a" : Symbol("a", Decl(contextualTypeInObjectProperty.ts, 0, 14)) |
| 7 | +>a : Symbol(a, Decl(contextualTypeInObjectProperty.ts, 1, 11)) |
| 8 | + |
| 9 | + "b"?: (b: "b") => "b"; |
| 10 | +>"b" : Symbol("b", Decl(contextualTypeInObjectProperty.ts, 1, 26)) |
| 11 | +>b : Symbol(b, Decl(contextualTypeInObjectProperty.ts, 2, 11)) |
| 12 | + |
| 13 | + "c"?: (c: "c") => "c"; |
| 14 | +>"c" : Symbol("c", Decl(contextualTypeInObjectProperty.ts, 2, 26)) |
| 15 | +>c : Symbol(c, Decl(contextualTypeInObjectProperty.ts, 3, 11)) |
| 16 | + |
| 17 | +}; |
| 18 | + |
| 19 | +const getC = () => "c" as const; |
| 20 | +>getC : Symbol(getC, Decl(contextualTypeInObjectProperty.ts, 6, 5)) |
| 21 | +>const : Symbol(const) |
| 22 | + |
| 23 | +export const obj: Shape = { |
| 24 | +>obj : Symbol(obj, Decl(contextualTypeInObjectProperty.ts, 8, 12)) |
| 25 | +>Shape : Symbol(Shape, Decl(contextualTypeInObjectProperty.ts, 0, 0)) |
| 26 | + |
| 27 | + ["a"]: keyA => keyA, |
| 28 | +>["a"] : Symbol(["a"], Decl(contextualTypeInObjectProperty.ts, 8, 27)) |
| 29 | +>"a" : Symbol(["a"], Decl(contextualTypeInObjectProperty.ts, 8, 27)) |
| 30 | +>keyA : Symbol(keyA, Decl(contextualTypeInObjectProperty.ts, 9, 8)) |
| 31 | +>keyA : Symbol(keyA, Decl(contextualTypeInObjectProperty.ts, 9, 8)) |
| 32 | + |
| 33 | + ["b" as "b"]: keyB => keyB, |
| 34 | +>["b" as "b"] : Symbol(["b" as "b"], Decl(contextualTypeInObjectProperty.ts, 9, 22)) |
| 35 | +>keyB : Symbol(keyB, Decl(contextualTypeInObjectProperty.ts, 10, 15)) |
| 36 | +>keyB : Symbol(keyB, Decl(contextualTypeInObjectProperty.ts, 10, 15)) |
| 37 | + |
| 38 | + [getC()]: keyC => keyC, |
| 39 | +>[getC()] : Symbol([getC()], Decl(contextualTypeInObjectProperty.ts, 10, 29)) |
| 40 | +>getC : Symbol(getC, Decl(contextualTypeInObjectProperty.ts, 6, 5)) |
| 41 | +>keyC : Symbol(keyC, Decl(contextualTypeInObjectProperty.ts, 11, 11)) |
| 42 | +>keyC : Symbol(keyC, Decl(contextualTypeInObjectProperty.ts, 11, 11)) |
| 43 | + |
| 44 | +}; |
| 45 | + |
| 46 | + |
| 47 | +const getUnion = () => "b" as "b" | "c"; |
| 48 | +>getUnion : Symbol(getUnion, Decl(contextualTypeInObjectProperty.ts, 15, 5)) |
| 49 | + |
| 50 | +export const unionType: Shape = { |
| 51 | +>unionType : Symbol(unionType, Decl(contextualTypeInObjectProperty.ts, 17, 12)) |
| 52 | +>Shape : Symbol(Shape, Decl(contextualTypeInObjectProperty.ts, 0, 0)) |
| 53 | + |
| 54 | + [getUnion()]: keyC => keyC, // Error |
| 55 | +>[getUnion()] : Symbol([getUnion()], Decl(contextualTypeInObjectProperty.ts, 17, 33)) |
| 56 | +>getUnion : Symbol(getUnion, Decl(contextualTypeInObjectProperty.ts, 15, 5)) |
| 57 | +>keyC : Symbol(keyC, Decl(contextualTypeInObjectProperty.ts, 18, 15)) |
| 58 | +>keyC : Symbol(keyC, Decl(contextualTypeInObjectProperty.ts, 18, 15)) |
| 59 | + |
| 60 | +}; |
| 61 | + |
| 62 | + |
| 63 | +export const func: Shape = { |
| 64 | +>func : Symbol(func, Decl(contextualTypeInObjectProperty.ts, 22, 12)) |
| 65 | +>Shape : Symbol(Shape, Decl(contextualTypeInObjectProperty.ts, 0, 0)) |
| 66 | + |
| 67 | + [getC]: keyC => keyC, // Error |
| 68 | +>[getC] : Symbol([getC], Decl(contextualTypeInObjectProperty.ts, 22, 28)) |
| 69 | +>getC : Symbol(getC, Decl(contextualTypeInObjectProperty.ts, 6, 5)) |
| 70 | +>keyC : Symbol(keyC, Decl(contextualTypeInObjectProperty.ts, 23, 9)) |
| 71 | +>keyC : Symbol(keyC, Decl(contextualTypeInObjectProperty.ts, 23, 9)) |
| 72 | + |
| 73 | +}; |
| 74 | + |
| 75 | +const generic: { |
| 76 | +>generic : Symbol(generic, Decl(contextualTypeInObjectProperty.ts, 26, 5)) |
| 77 | + |
| 78 | + c: <T>(arg: T) => T; |
| 79 | +>c : Symbol(c, Decl(contextualTypeInObjectProperty.ts, 26, 16)) |
| 80 | +>T : Symbol(T, Decl(contextualTypeInObjectProperty.ts, 27, 6)) |
| 81 | +>arg : Symbol(arg, Decl(contextualTypeInObjectProperty.ts, 27, 9)) |
| 82 | +>T : Symbol(T, Decl(contextualTypeInObjectProperty.ts, 27, 6)) |
| 83 | +>T : Symbol(T, Decl(contextualTypeInObjectProperty.ts, 27, 6)) |
| 84 | + |
| 85 | +} = { |
| 86 | + [getC()]: keyC => keyC, |
| 87 | +>[getC()] : Symbol([getC()], Decl(contextualTypeInObjectProperty.ts, 28, 5)) |
| 88 | +>getC : Symbol(getC, Decl(contextualTypeInObjectProperty.ts, 6, 5)) |
| 89 | +>keyC : Symbol(keyC, Decl(contextualTypeInObjectProperty.ts, 29, 11)) |
| 90 | +>keyC : Symbol(keyC, Decl(contextualTypeInObjectProperty.ts, 29, 11)) |
| 91 | + |
| 92 | +}; |
| 93 | + |
| 94 | +const thisType = { |
| 95 | +>thisType : Symbol(thisType, Decl(contextualTypeInObjectProperty.ts, 32, 5)) |
| 96 | + |
| 97 | + [getC()]: function() { |
| 98 | +>[getC()] : Symbol([getC()], Decl(contextualTypeInObjectProperty.ts, 32, 18)) |
| 99 | +>getC : Symbol(getC, Decl(contextualTypeInObjectProperty.ts, 6, 5)) |
| 100 | + |
| 101 | + this.c(); |
| 102 | +>this.c : Symbol([getC()], Decl(contextualTypeInObjectProperty.ts, 32, 18)) |
| 103 | +>this : Symbol(thisType, Decl(contextualTypeInObjectProperty.ts, 32, 16)) |
| 104 | +>c : Symbol([getC()], Decl(contextualTypeInObjectProperty.ts, 32, 18)) |
| 105 | + } |
| 106 | +}; |
| 107 | + |
| 108 | + |
| 109 | +declare function f<T extends object>(data: T, handlers: { [P in keyof T]: (value: T[P], prop: P) => void; }): void; |
| 110 | +>f : Symbol(f, Decl(contextualTypeInObjectProperty.ts, 36, 2)) |
| 111 | +>T : Symbol(T, Decl(contextualTypeInObjectProperty.ts, 39, 19)) |
| 112 | +>data : Symbol(data, Decl(contextualTypeInObjectProperty.ts, 39, 37)) |
| 113 | +>T : Symbol(T, Decl(contextualTypeInObjectProperty.ts, 39, 19)) |
| 114 | +>handlers : Symbol(handlers, Decl(contextualTypeInObjectProperty.ts, 39, 45)) |
| 115 | +>P : Symbol(P, Decl(contextualTypeInObjectProperty.ts, 39, 59)) |
| 116 | +>T : Symbol(T, Decl(contextualTypeInObjectProperty.ts, 39, 19)) |
| 117 | +>value : Symbol(value, Decl(contextualTypeInObjectProperty.ts, 39, 75)) |
| 118 | +>T : Symbol(T, Decl(contextualTypeInObjectProperty.ts, 39, 19)) |
| 119 | +>P : Symbol(P, Decl(contextualTypeInObjectProperty.ts, 39, 59)) |
| 120 | +>prop : Symbol(prop, Decl(contextualTypeInObjectProperty.ts, 39, 87)) |
| 121 | +>P : Symbol(P, Decl(contextualTypeInObjectProperty.ts, 39, 59)) |
| 122 | + |
| 123 | +f({ data: 0 }, { |
| 124 | +>f : Symbol(f, Decl(contextualTypeInObjectProperty.ts, 36, 2)) |
| 125 | +>data : Symbol(data, Decl(contextualTypeInObjectProperty.ts, 40, 3)) |
| 126 | + |
| 127 | + [(() => 'data' as const)()](value, key) { |
| 128 | +>[(() => 'data' as const)()] : Symbol([(() => 'data' as const)()], Decl(contextualTypeInObjectProperty.ts, 40, 16)) |
| 129 | +>const : Symbol(const) |
| 130 | +>value : Symbol(value, Decl(contextualTypeInObjectProperty.ts, 41, 30)) |
| 131 | +>key : Symbol(key, Decl(contextualTypeInObjectProperty.ts, 41, 36)) |
| 132 | + |
| 133 | + }, |
| 134 | +}); |
| 135 | + |
| 136 | + |
| 137 | +enum Keys { |
| 138 | +>Keys : Symbol(Keys, Decl(contextualTypeInObjectProperty.ts, 44, 3)) |
| 139 | + |
| 140 | + FIRST, |
| 141 | +>FIRST : Symbol(Keys.FIRST, Decl(contextualTypeInObjectProperty.ts, 47, 11)) |
| 142 | + |
| 143 | + SECOND |
| 144 | +>SECOND : Symbol(Keys.SECOND, Decl(contextualTypeInObjectProperty.ts, 48, 8)) |
| 145 | +} |
| 146 | + |
| 147 | +const obj2: { |
| 148 | +>obj2 : Symbol(obj2, Decl(contextualTypeInObjectProperty.ts, 52, 5)) |
| 149 | + |
| 150 | + [key in Keys]: [string, string] |
| 151 | +>key : Symbol(key, Decl(contextualTypeInObjectProperty.ts, 53, 3)) |
| 152 | +>Keys : Symbol(Keys, Decl(contextualTypeInObjectProperty.ts, 44, 3)) |
| 153 | + |
| 154 | +} = { |
| 155 | + [Keys.FIRST]: ['1', '2'], |
| 156 | +>[Keys.FIRST] : Symbol([Keys.FIRST], Decl(contextualTypeInObjectProperty.ts, 54, 5)) |
| 157 | +>Keys.FIRST : Symbol(Keys.FIRST, Decl(contextualTypeInObjectProperty.ts, 47, 11)) |
| 158 | +>Keys : Symbol(Keys, Decl(contextualTypeInObjectProperty.ts, 44, 3)) |
| 159 | +>FIRST : Symbol(Keys.FIRST, Decl(contextualTypeInObjectProperty.ts, 47, 11)) |
| 160 | + |
| 161 | + [Keys['SECOND']]: ['3', '4'] |
| 162 | +>[Keys['SECOND']] : Symbol([Keys['SECOND']], Decl(contextualTypeInObjectProperty.ts, 55, 27)) |
| 163 | +>Keys : Symbol(Keys, Decl(contextualTypeInObjectProperty.ts, 44, 3)) |
| 164 | +>'SECOND' : Symbol(Keys.SECOND, Decl(contextualTypeInObjectProperty.ts, 48, 8)) |
| 165 | +} |
| 166 | + |
0 commit comments