π Search Terms
Switch, Switch expression
β
Viability Checklist
β Suggestion
A switch expression like C# or any language.
So i can avoid using Immediately Invoked Function Expression
π Motivating Example
Instead of doing this
type State = 'loading' | 'success' | 'error';
const uiMessage = (() => {
const state: State = 'success';
switch (state) {
case 'loading': return 'Fetching data...';
case 'success': return 'Data loaded!';
default:
return 'Unknown error';
}
})();
let's do this, like C#
type State = 'loading' | 'success' | 'error';
const uiMessage: string = state switch {
'loading' => 'Fetching data...',
'success' => return 'Data loaded!',
default => 'Unknown error',
}
### π» Use Cases
1. What do you want to use this for?
3. What shortcomings exist with current approaches?
4. What workarounds are you using in the meantime?
π Search Terms
Switch, Switch expression
β Viability Checklist
β Suggestion
A switch expression like C# or any language.
So i can avoid using Immediately Invoked Function Expression
π Motivating Example
Instead of doing this
let's do this, like C#