File: controlFlowAssignmentExpression.types

package info (click to toggle)
node-typescript 5.0.4%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 459,116 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (78 lines) | stat: -rw-r--r-- 1,435 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
66
67
68
69
70
71
72
73
74
75
76
77
78
=== tests/cases/conformance/controlFlow/controlFlowAssignmentExpression.ts ===
let x: string | boolean | number;
>x : string | number | boolean

let obj: any;
>obj : any

x = "";
>x = "" : ""
>x : string | number | boolean
>"" : ""

x = x.length;
>x = x.length : number
>x : string | number | boolean
>x.length : number
>x : string
>length : number

x; // number
>x : number

x = true;
>x = true : true
>x : string | number | boolean
>true : true

(x = "", obj).foo = (x = x.length);
>(x = "", obj).foo = (x = x.length) : number
>(x = "", obj).foo : any
>(x = "", obj) : any
>x = "", obj : any
>x = "" : ""
>x : string | number | boolean
>"" : ""
>obj : any
>foo : any
>(x = x.length) : number
>x = x.length : number
>x : string | number | boolean
>x.length : number
>x : string
>length : number

x; // number
>x : number

// https://github.com/microsoft/TypeScript/issues/35484
type D = { done: true, value: 1 } | { done: false, value: 2 };
>D : { done: true; value: 1; } | { done: false; value: 2; }
>done : true
>true : true
>value : 1
>done : false
>false : false
>value : 2

declare function fn(): D;
>fn : () => D

let o: D;
>o : D

if ((o = fn()).done) {
>(o = fn()).done : boolean
>(o = fn()) : D
>o = fn() : D
>o : D
>fn() : D
>fn : () => D
>done : boolean

    const y: 1 = o.value;
>y : 1
>o.value : 1
>o : { done: true; value: 1; }
>value : 1
}