Closed STRd6 closed 2 weeks ago
How do you imagine distinguishing the indented type from the indented body of the function? I believe this is ambiguous in general...
As a workaround, you can use parentheses around the type for now.
Here's another fun way to write it (but still requires parens):
function O<T>(v: T): (
if T extends boolean
ObservableBoolean<T>
else if T extends number
ObservableNumber<T>
else
ObservableValue<T>
)
The colon makes this mostly unambiguous. Here's something that works already:
function O<T>(v: T): T extends boolean ? ObservableBoolean<T> :
T extends number ? ObservableNumber<T> :
ObservableValue<T>
v
When adding a nested type annotation the parser fails to pick it up:
This is useful in cases where there are more complex types and having the additional newline makes it easier to see what's going on.