Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bug: Typescript compiler is confused between Tuple literal and Array Literal #27074

Closed
wongjiahau opened this issue Sep 13, 2018 · 4 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@ghost
Copy link

ghost commented Sep 13, 2018

Duplicate of #11152 -- the problem is that annotating the result as OK<[string, number]> has no effect in the inferred type argument. let result = ok<[string, number]> (["hello", 12]); would work though.

@ghost ghost added the Duplicate An existing issue was already created label Sep 13, 2018
@wongjiahau
Copy link
Author

Despite the solution provided by @Andy-MS , another workaround is as follows:

let result = ok(["hello", 12] as [string, number]);

@wongjiahau
Copy link
Author

Extra notes

This bug arises because ["hello", 12] is inferred as array (string | number)[] instead of tuple [string, number], so, to fix this bug the type inference algorithm must be situational.

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants