Skip to content
Discussion options

You must be logged in to vote

For the pagination case, one workaround is to keep the schema factory generic but apply the array default after the key type has been instantiated. This avoids forcing TypeScript to resolve ArkType's default-input calculation while K is still generic.

This version compiles with ArkType 2.2.9 and TypeScript 5.9.3 in strict mode, without a cast:

import { type, type Type } from "arktype"

function pagination<K extends string>(key: Type<K>) {
	const sortItems = type({
		key,
		order: '"asc" | "desc"'
	}).array().atLeastLength(1)

	return {
		sortItems,
		base: type({
			limit: "1 <= number.integer <= 100 = 20",
			"cursor?": "string"
		})
	}
}

const room = pagination(type('"updatedAt" | "name"'

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Q16solver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants