ForbesLindesay / funtypes

Runtime validation for static types
MIT License
29 stars 4 forks source link

Better handling of unions of literals/enums #33

Open ForbesLindesay opened 3 years ago

ForbesLindesay commented 3 years ago

It would be good to have a Runtype for Enum that could take an existing TypeScript enum and return a type for validating it.

It would also be possible to optimise unions of literals by generating a Set<string | number> up front to allow O(log(n)) lookup instead of linearly traversing the list. It might also be worth adding some form of caching to show.

ForbesLindesay commented 3 years ago

It should be able to handle cases where unions are nested and cases where one entry in the union has multiple possible literal values for a tag