Allow nesting user-defined type guards within a return object #47195
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Suggestion
π Search Terms
nested user-defined type guards
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
Currently, type guards can only return a boolean value (
x is SomeType
). I think it would be beneficial to allow this assertion to be nested within a more complex return type.Playground link
π Motivating Example
π» Use Cases
Currently, we have to either have to assert properties when we use them (
data.name!
) or we manually type-cast the object within the check:The text was updated successfully, but these errors were encountered: