File: controlFlowForInStatement2.types

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (65 lines) | stat: -rw-r--r-- 1,116 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
=== tests/cases/conformance/controlFlow/controlFlowForInStatement2.ts ===
const keywordA = 'a';
>keywordA : "a"
>'a' : "a"

const keywordB = 'b';
>keywordB : "b"
>'b' : "b"

type A = { [keywordA]: number };
>A : { a: number; }
>[keywordA] : number
>keywordA : "a"

type B = { [keywordB]: string };
>B : { b: string; }
>[keywordB] : string
>keywordB : "b"

declare const c: A | B;
>c : A | B

if ('a' in c) {
>'a' in c : boolean
>'a' : "a"
>c : A | B

    c; // narrowed to `A`
>c : A
}

if (keywordA in c) {
>keywordA in c : boolean
>keywordA : "a"
>c : A | B

    c; // also narrowed to `A`
>c : A
}

let stringB: string = 'b';
>stringB : string
>'b' : "b"

if ((stringB as 'b') in c) {
>(stringB as 'b') in c : boolean
>(stringB as 'b') : "b"
>stringB as 'b' : "b"
>stringB : string
>c : A | B

    c; // narrowed to `B`
>c : B
}

if ((stringB as ('a' | 'b')) in c) {
>(stringB as ('a' | 'b')) in c : boolean
>(stringB as ('a' | 'b')) : "a" | "b"
>stringB as ('a' | 'b') : "a" | "b"
>stringB : string
>c : A | B

    c; // not narrowed
>c : A | B
}