How to merge types with Generics

I'm trying hard to understand how to work with generics (arktype and typescipt too).
export const paginationRequest = <
const def extends object,
$ = {},
>(
filter?: type.validate<def, $>,
) => {
return type("<t>", {
page: "number.integer > 0",
limit: "number.integer > 0",
filter: "t", // Also i want this field won't appear if filter value is undefined in function
})(
filter // Here's type error: Type string is not assignable to type validateTuple<[def], {}, bindThis<[def]>>
);
};
export const paginationRequest = <
const def extends object,
$ = {},
>(
filter?: type.validate<def, $>,
) => {
return type("<t>", {
page: "number.integer > 0",
limit: "number.integer > 0",
filter: "t", // Also i want this field won't appear if filter value is undefined in function
})(
filter // Here's type error: Type string is not assignable to type validateTuple<[def], {}, bindThis<[def]>>
);
};
1 Reply
ssalbdivad
ssalbdivad4d ago
ArkType
ArkType Docs
TypeScript's 1:1 validator, optimized from editor to runtime

Did you find this page helpful?