-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tuple narrowing is lost when wrapped in Promise #27363
Comments
The interface PromiseConstructor {
resolve<T extends unknown[] | [unknown]>(value: T | PromiseLike<T>): Promise<T>;
} Be aware that, probably, any array created inside |
Declaration merging didn't work because the tuple overload needs to come first. When I manually inserted it into the declaration for interface PromiseConstructor {
....
resolve<T extends unknown[] | [unknown]>(value: T | PromiseLike<T>): Promise<T>;
resolve<T>(value: T | PromiseLike<T>): Promise<T>;
...
} Yuck. This demonstrates the problem with having to depend on a construct like |
Also discussed at #27486 We can't just infer tuples everywhere (it breaks everything). |
What is your recommendation on how to code |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
TypeScript Version:
3.2.0-dev.20180926
Search Terms
tuple array narrow
Code
Expected behavior:
The call to
goofus
to behave like the call togallant
-- ARGS should narrow to the tuple[number, string]
and thusx
is anumber
andy
is astring
Actual behavior:
In the call to
goofus
,ARGS === (number | string)[]
, and so bothx
andy
arenumber | string
, which results in the following error:Playground Link:
link
Related Issues:
The
T extends XXX[] | [XXX]
syntax for tuple narrowing is per @ahejlsberg in #27179The text was updated successfully, but these errors were encountered: