Feature Request: Improve type narrowing for class instances inside switch-case expressions #49188
Closed
5 tasks done
Labels
Duplicate
An existing issue was already created
Uh oh!
There was an error while loading. Please reload this page.
Suggestion
π Search Terms
constructor
,instanceof
,switch
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
Add type narrowing based on object constructor in
switch case
expressions.π Motivating Example
Let's imagine we have 2 dedicated parts of our codebase:
It may be useful to use
switch case
expression for handling incoming objects instead of using multipletype guards
:Using switch case
Using type guards
π» Use Cases
This feature is required in event-driven architectures. Here goes a sample:
Sample
The text was updated successfully, but these errors were encountered: