|
| 1 | +=== tests/cases/compiler/twiceNestedKeyofIndexInference.ts === |
| 2 | +type Set1<T, K1 extends keyof T> = T extends any[] ? T : Pick<T, Exclude<keyof T, K1>> & { |
| 3 | +>Set1 : Symbol(Set1, Decl(twiceNestedKeyofIndexInference.ts, 0, 0)) |
| 4 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 0, 10)) |
| 5 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 0, 12)) |
| 6 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 0, 10)) |
| 7 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 0, 10)) |
| 8 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 0, 10)) |
| 9 | +>Pick : Symbol(Pick, Decl(lib.es5.d.ts, --, --)) |
| 10 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 0, 10)) |
| 11 | +>Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --)) |
| 12 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 0, 10)) |
| 13 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 0, 12)) |
| 14 | + |
| 15 | + [SK1 in K1]-?: Required<Pick<T, SK1>>; |
| 16 | +>SK1 : Symbol(SK1, Decl(twiceNestedKeyofIndexInference.ts, 1, 5)) |
| 17 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 0, 12)) |
| 18 | +>Required : Symbol(Required, Decl(lib.es5.d.ts, --, --)) |
| 19 | +>Pick : Symbol(Pick, Decl(lib.es5.d.ts, --, --)) |
| 20 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 0, 10)) |
| 21 | +>SK1 : Symbol(SK1, Decl(twiceNestedKeyofIndexInference.ts, 1, 5)) |
| 22 | + |
| 23 | +}[K1]; |
| 24 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 0, 12)) |
| 25 | + |
| 26 | +type Set2<T, K1 extends keyof T, K2 extends keyof T[K1]> = T extends any[] ? T : Pick<T, Exclude<keyof T, K1>> & { |
| 27 | +>Set2 : Symbol(Set2, Decl(twiceNestedKeyofIndexInference.ts, 2, 6)) |
| 28 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 4, 10)) |
| 29 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 4, 12)) |
| 30 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 4, 10)) |
| 31 | +>K2 : Symbol(K2, Decl(twiceNestedKeyofIndexInference.ts, 4, 32)) |
| 32 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 4, 10)) |
| 33 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 4, 12)) |
| 34 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 4, 10)) |
| 35 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 4, 10)) |
| 36 | +>Pick : Symbol(Pick, Decl(lib.es5.d.ts, --, --)) |
| 37 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 4, 10)) |
| 38 | +>Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --)) |
| 39 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 4, 10)) |
| 40 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 4, 12)) |
| 41 | + |
| 42 | + [SK1 in K1]-?: Required<{ |
| 43 | +>SK1 : Symbol(SK1, Decl(twiceNestedKeyofIndexInference.ts, 5, 5)) |
| 44 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 4, 12)) |
| 45 | +>Required : Symbol(Required, Decl(lib.es5.d.ts, --, --)) |
| 46 | + |
| 47 | + [key in K1]: Set1<T[K1], K2>; |
| 48 | +>key : Symbol(key, Decl(twiceNestedKeyofIndexInference.ts, 6, 9)) |
| 49 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 4, 12)) |
| 50 | +>Set1 : Symbol(Set1, Decl(twiceNestedKeyofIndexInference.ts, 0, 0)) |
| 51 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 4, 10)) |
| 52 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 4, 12)) |
| 53 | +>K2 : Symbol(K2, Decl(twiceNestedKeyofIndexInference.ts, 4, 32)) |
| 54 | + |
| 55 | + }>; |
| 56 | +}[K1]; |
| 57 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 4, 12)) |
| 58 | + |
| 59 | +declare function set<T, K1 extends keyof T>(source: T, path: [K1], value: T[K1]): Set1<T, K1>; |
| 60 | +>set : Symbol(set, Decl(twiceNestedKeyofIndexInference.ts, 8, 6), Decl(twiceNestedKeyofIndexInference.ts, 10, 94)) |
| 61 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 10, 21)) |
| 62 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 10, 23)) |
| 63 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 10, 21)) |
| 64 | +>source : Symbol(source, Decl(twiceNestedKeyofIndexInference.ts, 10, 44)) |
| 65 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 10, 21)) |
| 66 | +>path : Symbol(path, Decl(twiceNestedKeyofIndexInference.ts, 10, 54)) |
| 67 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 10, 23)) |
| 68 | +>value : Symbol(value, Decl(twiceNestedKeyofIndexInference.ts, 10, 66)) |
| 69 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 10, 21)) |
| 70 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 10, 23)) |
| 71 | +>Set1 : Symbol(Set1, Decl(twiceNestedKeyofIndexInference.ts, 0, 0)) |
| 72 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 10, 21)) |
| 73 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 10, 23)) |
| 74 | + |
| 75 | +declare function set<T, K1 extends keyof T, K2 extends keyof T[K1]>(source: T, path: [K1, K2], value: T[K1][K2]): Set2<T, K1, K2>; |
| 76 | +>set : Symbol(set, Decl(twiceNestedKeyofIndexInference.ts, 8, 6), Decl(twiceNestedKeyofIndexInference.ts, 10, 94)) |
| 77 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 12, 21)) |
| 78 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 12, 23)) |
| 79 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 12, 21)) |
| 80 | +>K2 : Symbol(K2, Decl(twiceNestedKeyofIndexInference.ts, 12, 43)) |
| 81 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 12, 21)) |
| 82 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 12, 23)) |
| 83 | +>source : Symbol(source, Decl(twiceNestedKeyofIndexInference.ts, 12, 68)) |
| 84 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 12, 21)) |
| 85 | +>path : Symbol(path, Decl(twiceNestedKeyofIndexInference.ts, 12, 78)) |
| 86 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 12, 23)) |
| 87 | +>K2 : Symbol(K2, Decl(twiceNestedKeyofIndexInference.ts, 12, 43)) |
| 88 | +>value : Symbol(value, Decl(twiceNestedKeyofIndexInference.ts, 12, 94)) |
| 89 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 12, 21)) |
| 90 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 12, 23)) |
| 91 | +>K2 : Symbol(K2, Decl(twiceNestedKeyofIndexInference.ts, 12, 43)) |
| 92 | +>Set2 : Symbol(Set2, Decl(twiceNestedKeyofIndexInference.ts, 2, 6)) |
| 93 | +>T : Symbol(T, Decl(twiceNestedKeyofIndexInference.ts, 12, 21)) |
| 94 | +>K1 : Symbol(K1, Decl(twiceNestedKeyofIndexInference.ts, 12, 23)) |
| 95 | +>K2 : Symbol(K2, Decl(twiceNestedKeyofIndexInference.ts, 12, 43)) |
| 96 | + |
| 97 | + |
| 98 | +interface State { |
| 99 | +>State : Symbol(State, Decl(twiceNestedKeyofIndexInference.ts, 12, 130)) |
| 100 | + |
| 101 | + a: { |
| 102 | +>a : Symbol(State.a, Decl(twiceNestedKeyofIndexInference.ts, 15, 17)) |
| 103 | + |
| 104 | + b: string; |
| 105 | +>b : Symbol(b, Decl(twiceNestedKeyofIndexInference.ts, 16, 8)) |
| 106 | + |
| 107 | + c: number; |
| 108 | +>c : Symbol(c, Decl(twiceNestedKeyofIndexInference.ts, 17, 18)) |
| 109 | + |
| 110 | + }; |
| 111 | + d: boolean; |
| 112 | +>d : Symbol(State.d, Decl(twiceNestedKeyofIndexInference.ts, 19, 6)) |
| 113 | +} |
| 114 | + |
| 115 | +const state: State = { |
| 116 | +>state : Symbol(state, Decl(twiceNestedKeyofIndexInference.ts, 23, 5)) |
| 117 | +>State : Symbol(State, Decl(twiceNestedKeyofIndexInference.ts, 12, 130)) |
| 118 | + |
| 119 | + a: { |
| 120 | +>a : Symbol(a, Decl(twiceNestedKeyofIndexInference.ts, 23, 22)) |
| 121 | + |
| 122 | + b: "", |
| 123 | +>b : Symbol(b, Decl(twiceNestedKeyofIndexInference.ts, 24, 8)) |
| 124 | + |
| 125 | + c: 0, |
| 126 | +>c : Symbol(c, Decl(twiceNestedKeyofIndexInference.ts, 25, 14)) |
| 127 | + |
| 128 | + }, |
| 129 | + d: false, |
| 130 | +>d : Symbol(d, Decl(twiceNestedKeyofIndexInference.ts, 27, 6)) |
| 131 | + |
| 132 | +}; |
| 133 | + |
| 134 | +const newState: State = set(state, ["a", 'b'], 'why'); // shouldn't be an error |
| 135 | +>newState : Symbol(newState, Decl(twiceNestedKeyofIndexInference.ts, 31, 5)) |
| 136 | +>State : Symbol(State, Decl(twiceNestedKeyofIndexInference.ts, 12, 130)) |
| 137 | +>set : Symbol(set, Decl(twiceNestedKeyofIndexInference.ts, 8, 6), Decl(twiceNestedKeyofIndexInference.ts, 10, 94)) |
| 138 | +>state : Symbol(state, Decl(twiceNestedKeyofIndexInference.ts, 23, 5)) |
| 139 | + |
0 commit comments