-
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
Different return types for Ternary/Conditional Operator #1462
Comments
@AbubakerB Great feedback. Several points.
|
Thanks for the response. As for 1), i understand your point. I guess the reason why i brought this up, is because i see this as valid javascript and i didn't see it going against any of the specs (or maybe i didn't look good enough). for 2) cool, i'll be looking forward to it! and 3) Thanks! |
Regarding union types and the conditional operator, in (the upcoming) version 1.4 this does indeed produce a union type result: var result = true ? aye() : bee(); // type of result is number | void The changes are already in the master branch and the spec. https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#4.16 |
Sounds like all these issues have been addressed. |
I have a few questions regarding the return type and validity of the conditional operator.
Consider the following:
This will throw an error stating "No best common type exists between 'number' and 'void'.".
I was wondering why it would thrown an error if all we're doing is evaluating the {Expressions} (in this case; calling those functions) while not caring about the return type.
I could understand the following throwing an error:
but why should it throw an error if we don't care about the return type? I'm curious about the decision of this validation/error.
(note: i understand using any will solve this)
In addition, now with the introduction of Union Types in 1.4 (#805), i assume the following will be valid?
On a related note. The indentation for conditional operators is as so:
instead of tabbing the '?' and ':' (as C# does) - is this by design?
The text was updated successfully, but these errors were encountered: