Allow decorators to apply type guards to arguments of the method/function they decorate #50159
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
Bug Report
π Search Terms
decorators, type guards
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
TypeScript throws the error
Type 'undefined' is not assignable to type 'string'.
when person.name is used as a parameter to a method guarded by the@isNamePresent
decoratorπ Expected behavior
TypeScript should see the decorator's type guard show the person.name field as only being a string, not
string | undefined
.This could be too closely related to function calls not resetting narrowing, in which case, just close this issue. Though I do think it is different enough where it might be possible to be fixed.
The text was updated successfully, but these errors were encountered: