Skip to content
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

When in function argument, array of union produces different type error to when in instantiation of same type #27855

Closed
yseymour opened this issue Oct 12, 2018 · 1 comment
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging
Milestone

Comments

@yseymour
Copy link

Mild title gore, sorry.

TypeScript Version: 3.2.0-dev.201xxxxx

Search Terms: array union type error

Code

type Foo = 'A' | 'B';
const foo_list: Foo[] = ['A', 'X'];  // Error: Type '"X"' is not assignable to type 'Foo'
declare function bar(x: Foo[]);
bar(['A', 'X']); // Error (x2): Type 'string' is not assignable to type 'Foo'

Expected behavior:
Same error on line 4 as on line 2

Actual behavior:
All elements of the array are highlighted as errors instead, making it difficult to spot which one is wrong.

Playground Link: http://www.typescriptlang.org/play/#src=type%20Foo%20%3D%20'A'%20%7C%20'B'%3B%0Aconst%20foo_list%3A%20Foo%5B%5D%20%3D%20%5B'A'%2C%20'X'%5D%3B%0Adeclare%20function%20bar(x%3A%20Foo%5B%5D)%3B%0Abar(%5B'A'%2C%20'X'%5D)%3B%0A

Related Issues: Probably #26077 or one of its constituents

@ghost ghost added Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging labels Oct 12, 2018
@RyanCavanaugh RyanCavanaugh added this to the Future milestone Oct 12, 2018
@yseymour
Copy link
Author

yseymour commented Jun 6, 2020

This is a bit old, but I'm happy to report it appears to be fixed.

@yseymour yseymour closed this as completed Jun 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging
Projects
None yet
Development

No branches or pull requests

2 participants