Skip to content

Commit a439e62

Browse files
committed
Add tests
1 parent dcd225a commit a439e62

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/cases/conformance/types/keyof/keyofAndIndexedAccess.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,46 @@ function f40(c: C) {
181181
let z: Z = c["z"];
182182
}
183183

184+
function f50<T>(k: keyof T, s: string, n: number) {
185+
const x1 = s as keyof T;
186+
const x2 = n as keyof T;
187+
const x3 = k as string;
188+
const x4 = k as number;
189+
const x5 = k as string | number;
190+
}
191+
192+
function f51<T, K extends keyof T>(k: K, s: string, n: number) {
193+
const x1 = s as keyof T;
194+
const x2 = n as keyof T;
195+
const x3 = k as string;
196+
const x4 = k as number;
197+
const x5 = k as string | number;
198+
}
199+
200+
function f52<T>(obj: { [x: string]: boolean }, k: keyof T, s: string, n: number) {
201+
const x1 = obj[s];
202+
const x2 = obj[n];
203+
const x3 = obj[k];
204+
}
205+
206+
function f53<T, K extends keyof T>(obj: { [x: string]: boolean }, k: K, s: string, n: number) {
207+
const x1 = obj[s];
208+
const x2 = obj[n];
209+
const x3 = obj[k];
210+
}
211+
212+
function f54<T>(obj: T, key: keyof T) {
213+
for (let s in obj[key]) {
214+
}
215+
const b = "foo" in obj[key];
216+
}
217+
218+
function f55<T, K extends keyof T>(obj: T, key: K) {
219+
for (let s in obj[key]) {
220+
}
221+
const b = "foo" in obj[key];
222+
}
223+
184224
// Repros from #12011
185225

186226
class Base {

0 commit comments

Comments
 (0)