TypeScript Version:
1.8.9
Code
Promise.all([Promise.resolve('')]); // has type Promise<Promise<string>[]>
Expected behavior:
The expression has type Promise<string[]> as in 1.8.7
Actual behavior:
The expression has type Promise<Promise<string>[]>
+1
This is a regression in 1.8.9.
Our build pipeline has a dep. on TS ~1.8.0.
When 1.8.9 was fetched we started getting type errors in code like this:
let [{ content: x }, { content: y }] = Promise.all([fetch('x'), fetch('y')]);
// error TS2459: Type 'Promise<HttpResponseMessage>' has no property 'content' and no string index signature
I have a reproducible example here: https://gist.github.com/MarcusNoble/522b1fea7077be0af59a
This is caused by 1589e4f57e39aa6c5bb9e0be39f60191cf94f8b9 limiting the depth of type inference to 5. There is no way of overriding this behaviour.
@vladima Are you able to weigh in on this?
yes, I can repro this. To give some more context - originally depth limit was set to fix #7081. Value of depth was somewhat arbitrary - all large codebases that we have for tests worked fine with depth = 3 so with depth=5 we have some safety net. Apparently it was not enough. I propose to set the depth to 10 (current example starts working with depth=6). It still give a reasonable time on the test case from the original bug, I'll post time measurements later today, need to find them in mail.
// cc: @mhegazy
I don't fully understand what happens under the hood here, but is this error message the one you'd expect? Shouldn't we have some kind of "type inference failed" error (or at least warning) for cases that go beyond whatever depth you set?
It is a bit surprising and unhelpful that TS decides the expression is Promise<T>[] when it is T[] without a warning. A message about failing to infer would have led me to the workaround of specifying types explicitly.
A bug fix release as 1.8.10 would be nice.
Has this made 1.8.10?
still reproduce at 1.8.10 version
getResults(): Promise<string[]> {
const results: string[] = [];
const promises = results.map(result => {
return Promise.resolve(result);
});
return Promise.all(promises);
}
error TS2322: Type 'Promise<Promise<string>[]>' is not assignable to type 'Promise<string[]>'.
Type 'Promise<string>[]' is not assignable to type 'string[]'.
Type 'Promise<string>' is not assignable to type 'string'.
The fix is in TS 2.0 as noted from the "Milestone".
Any workaround until 2.0 is released?
Revert to typescript 1.8.7 is what I had to do
Just confirm that the bug still can be reproduced in 1.8.10.
What I did is that set the TAll explicitly.

Most helpful comment
Just confirm that the bug still can be reproduced in 1.8.10.
What I did is that set the TAll explicitly.