arktype
arktype copied to clipboard
Support generics, add builtins like Partial
This is the API I'm envisioning:
scope({
"box<t>": {
box: "t"
},
boxedString: "box<string>"
})
There'd also be some way to define them using type syntax that I'll have to decide on, and a helper method like generic
.
Could also consider adding higher-kinded types, maybe something like this:
scope({
"box<t>": {
box: "t"
},
// accepts a generic that takes one parameter, and creates a generic that applies it twice
"nest<g><t>": "g<g<t>>",,
"nestedBox": "nest<box>"
"nestedString": "nestedBox<string>"
})
Generics should also be chainable from a type like this:
const myData = type({
a: {
x: number;
y: string;
z: {
w: number;
}
},
b: number;
c: string;
})
const modifiedData = myData.optionalize("a|x|w").omit("a|y").merge({b: "string"})