Checking assignability without losing inferred types and without runtime code #26045
Closed
4 tasks done
Labels
Duplicate
An existing issue was already created
Search Terms
type erase assert validat assign
Suggestion
Recently I've been using a construct like the following in order to validate structures against a determinate type while still keeping their inferred type:
Oh, and this sometimes even infers parameters for functions, saving the need for some type annotations.
This is different from writing something like
While
validateType
works great, it feels a bit hacky, since we need to create a "concrete" JS function in order to achieve that. It would be great if that type of check could be achieved just with type annotations. Example:I have used
extends
in the example here since it's an already existing keyword, if you come up with a better idea...thanks!
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: