Support for switch statement shorthand #61038
Labels
Suggestion
An idea for TypeScript
Too Complex
An issue which adding support for may be too complex for the value it adds
π Search Terms
"switch shorthand"
β Viability Checklist
β Suggestion
Support for type narrowing in
π Motivating Example
Imagine you need to narrow type of object from 2 possible options and access property based on that type. Easy solution - ternary.
Now another option is added. Easy solution - extend ternary by another check.
And few more options are added. Extending ternary any more will make it hard to read. Switch statement is easier to read, but it requires to declare variable first and then assign something to it based on condition.
But shorthand switch exists, similar to ternary. And it is not working with typescript.
Playground link or as code:
π» Use Cases
Main use case: one line switch statement.
Two workarounds: normal switch or long ternary.
The text was updated successfully, but these errors were encountered: