Skip to content

Commit efea81b

Browse files
committed
Add failing repro
1 parent 19e88ac commit efea81b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// @strictNullChecks: true
2+
3+
// Type guards involving type parameters produce intersection types
4+
5+
class C {
6+
prop: string;
7+
}
8+
9+
function f1<T>(x: T) {
10+
if (x instanceof C) {
11+
let v1: T = x;
12+
let v2: C = x;
13+
x.prop;
14+
}
15+
}
16+
17+
function f2<T>(x: T) {
18+
if (typeof x === "string") {
19+
let v1: T = x;
20+
let v2: string = x;
21+
x.length;
22+
}
23+
}
24+
25+
// Repro from #13872
26+
27+
function fun<T>(item: { [P in keyof T]: T[P] }) {
28+
const strings: string[] = [];
29+
for (const key in item) {
30+
const value = item[key];
31+
if (typeof value === "string") {
32+
strings.push(value);
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)