forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
controlFlowIterationErrorsAsync.errors.txt
177 lines (152 loc) · 6.23 KB
/
controlFlowIterationErrorsAsync.errors.txt
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
tests/cases/conformance/controlFlow/controlFlowIterationErrorsAsync.ts(11,23): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/controlFlow/controlFlowIterationErrorsAsync.ts(22,23): error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'.
Type 'number' is not assignable to type 'string'.
tests/cases/conformance/controlFlow/controlFlowIterationErrorsAsync.ts(34,23): error TS2769: No overload matches this call.
Overload 1 of 2, '(x: string): Promise<number>', gave the following error.
Argument of type 'string | number' is not assignable to parameter of type 'string'.
Type 'number' is not assignable to type 'string'.
Overload 2 of 2, '(x: number): Promise<string>', gave the following error.
Argument of type 'string | number' is not assignable to parameter of type 'number'.
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/controlFlow/controlFlowIterationErrorsAsync.ts(45,23): error TS2769: No overload matches this call.
Overload 1 of 2, '(x: string): Promise<number>', gave the following error.
Argument of type 'string | number' is not assignable to parameter of type 'string'.
Type 'number' is not assignable to type 'string'.
Overload 2 of 2, '(x: number): Promise<string>', gave the following error.
Argument of type 'string | number' is not assignable to parameter of type 'number'.
Type 'string' is not assignable to type 'number'.
==== tests/cases/conformance/controlFlow/controlFlowIterationErrorsAsync.ts (4 errors) ====
let cond: boolean;
async function len(s: string) {
return s.length;
}
async function f1() {
let x: string | number | boolean;
x = "";
while (cond) {
x = await len(x);
~
!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'.
!!! error TS2345: Type 'number' is not assignable to type 'string'.
x;
}
x;
}
async function f2() {
let x: string | number | boolean;
x = "";
while (cond) {
x;
x = await len(x);
~
!!! error TS2345: Argument of type 'string | number' is not assignable to parameter of type 'string'.
!!! error TS2345: Type 'number' is not assignable to type 'string'.
}
x;
}
declare function foo(x: string): Promise<number>;
declare function foo(x: number): Promise<string>;
async function g1() {
let x: string | number | boolean;
x = "";
while (cond) {
x = await foo(x);
~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(x: string): Promise<number>', gave the following error.
!!! error TS2769: Argument of type 'string | number' is not assignable to parameter of type 'string'.
!!! error TS2769: Type 'number' is not assignable to type 'string'.
!!! error TS2769: Overload 2 of 2, '(x: number): Promise<string>', gave the following error.
!!! error TS2769: Argument of type 'string | number' is not assignable to parameter of type 'number'.
!!! error TS2769: Type 'string' is not assignable to type 'number'.
x;
}
x;
}
async function g2() {
let x: string | number | boolean;
x = "";
while (cond) {
x;
x = await foo(x);
~
!!! error TS2769: No overload matches this call.
!!! error TS2769: Overload 1 of 2, '(x: string): Promise<number>', gave the following error.
!!! error TS2769: Argument of type 'string | number' is not assignable to parameter of type 'string'.
!!! error TS2769: Type 'number' is not assignable to type 'string'.
!!! error TS2769: Overload 2 of 2, '(x: number): Promise<string>', gave the following error.
!!! error TS2769: Argument of type 'string | number' is not assignable to parameter of type 'number'.
!!! error TS2769: Type 'string' is not assignable to type 'number'.
}
x;
}
async function asNumber(x: string | number): Promise<number> {
return +x;
}
async function h1() {
let x: string | number | boolean;
x = "0";
while (cond) {
x = +x + 1;
x;
}
}
async function h2() {
let x: string | number | boolean;
x = "0";
while (cond) {
x = await asNumber(x) + 1;
x;
}
}
async function h3() {
let x: string | number | boolean;
x = "0";
while (cond) {
let y = await asNumber(x);
x = y + 1;
x;
}
}
async function h4() {
let x: string | number | boolean;
x = "0";
while (cond) {
x;
let y = await asNumber(x);
x = y + 1;
x;
}
}
// repro #51115
async function get_things(_: number | undefined) {
return [0];
}
async function foobar() {
let before: number | undefined = undefined;
for (let i = 0; i < 2; i++) {
const results = await get_things(before);
before = results[0];
}
}
// repro #43047#issuecomment-821453073
declare function foox(x: string | undefined): Promise<string>
async () => {
let bar: string | undefined = undefined;
do {
const baz = await foox(bar);
bar = baz
} while (bar)
}
// repro #43047#issuecomment-874221939
declare function myQuery(input: { lastId: number | undefined }): Promise<{ entities: number[] }>;
async function myFunc(): Promise<void> {
let lastId: number | undefined = undefined;
while (true) {
const { entities } = await myQuery({
lastId,
});
lastId = entities[entities.length - 1];
}
}