forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontrolFlowAssignmentExpression.js
More file actions
97 lines (83 loc) · 1.91 KB
/
controlFlowAssignmentExpression.js
File metadata and controls
97 lines (83 loc) · 1.91 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//// [controlFlowAssignmentExpression.ts]
let x: string | boolean | number;
let obj: any;
x = "";
x = x.length;
x; // number
x = true;
(x = "", obj).foo = (x = x.length);
x; // number
// https://github.com/microsoft/TypeScript/issues/35484
type D = { done: true, value: 1 } | { done: false, value: 2 };
declare function fn(): D;
let o: D;
if ((o = fn()).done) {
const y: 1 = o.value;
}
// https://github.com/microsoft/TypeScript/issues/47731
declare let a: object | any[] | undefined
if (a === undefined) {
a = []
} else if (!Array.isArray(a)) {
throw new Error()
}
[...a] // any[]
interface Parent {
parent: string;
}
interface Child extends Parent {
child: string;
}
declare let p: Parent;
declare let c: Child;
declare let y: Parent | Child | undefined;
y = p;
y; // Parent
y = c;
y; // Child
y = undefined as any as Parent | Child;
y; // Parent | Child
y = undefined as any as Parent | undefined;
y; // Parent | undefined
y = undefined as any as Child | undefined;
y; // Child | undefined
//// [controlFlowAssignmentExpression.js]
"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var x;
var obj;
x = "";
x = x.length;
x; // number
x = true;
(x = "", obj).foo = (x = x.length);
x; // number
var o;
if ((o = fn()).done) {
var y_1 = o.value;
}
if (a === undefined) {
a = [];
}
else if (!Array.isArray(a)) {
throw new Error();
}
__spreadArray([], a, true); // any[]
y = p;
y; // Parent
y = c;
y; // Child
y = undefined;
y; // Parent | Child
y = undefined;
y; // Parent | undefined
y = undefined;
y; // Child | undefined