We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 19e88ac commit efea81bCopy full SHA for efea81b
tests/cases/conformance/controlFlow/typeGuardsTypeParameters.ts
@@ -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
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