You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow explicitly specify the type of tested value based on the type of result.
π Motivating Example
This allows to break existing types into a user defined subtypes, for example for valid | invalid strings
functionisValidEmail(value: string): value is ValidEmailotherwiseInvalidEmail{return/^\S+@\S+\.\S+$/.test(value)}functionupdateEmail(email: ValidEmail){// ...}functionshowEmailFormatError(email: InvalidEmail){// ...}letemail=document.querySelector("#email").value;if(isValidEmail(email)){updateEmail(email);}else{// infers the type from otherwiseshowEmailFormatError(email)}
π Search Terms
else typeguard, typeguard properties
β Viability Checklist
β Suggestion
Allow explicitly specify the type of tested value based on the type of result.
π Motivating Example
This allows to break existing types into a user defined subtypes, for example for valid | invalid strings
Getting a response type based on a status
π» Use Cases
To ensure handling of special cases and validation.
Need of typecasting and boilerplate
The text was updated successfully, but these errors were encountered: