Generics
Keywords
Record is now available as a builtin keyword.
In addition to Record
, the following generics from TS are now available in ArkType:
- Pick
- Omit
- Extract
- Exclude
These can be instantiated in one of three ways:
Syntax
Definition
Constrained Parameters
All syntax in parameters definitions and all references to generic args are fully-type safe and autocompleted like any builtin keyword. Constraints can be used just like TS to limit what can be passed to a generic and allow that arg to be used with operators like >
.
Scoped
There is a special syntax for specifying generics in a scope:
Invocation
Chained
Invoked
HKT
Our new generics have been built using a new method for integrating arbitrary external types as native ArkType generics! This opens up tons of possibilities for external integrations that would otherwise not be possible. As a preview, here's what the implementation of Partial
looks like internally:
Recursive and cyclic generics are also currently unavailable and will be added soon.
For more usage examples, check out the unit tests for generics here.
This feature was built to be very robust and flexible. We're excited to see what you do with it!