-
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
Typing (string[] | string[][]) not recognized properly #6453
Comments
Methods are available on a union type only when each of the underlying methods have identical parameter lists (which isn't the case here). This is by design. From a typing perspective it technically isn't correct to do what you expected in all cases (i.e. union together the parameter types of each of the underlying methods). For example, say you had a method with two parameters of the array element type. The underlying signatures would be |
@ahejlsberg Maybe I'm at a loss, but why is
Of course, here you can't do I mean (and maybe OP, either), that here
What is the technical difference between |
string[] | number[] means either an array of string OR an array of number. (string | number)[] means an array of string OR number, in a non exclusive way. |
@ahejlsberg is there any notion of (co/contra)variance in typescript? I think something can come out from properly considering that aspect. In your example, we may also consider the signature as a whole: |
@mhegazy I think it could be reopened |
Hi all,
I have two small examples that I expected to be equivalent but tsc accepts only one:
Working example:
Not-working example:
The text was updated successfully, but these errors were encountered: