Generate fast-check arbitraries from ArkType schemas.
Install it alongside fast-check:
pnpm add arktype @ark/fast-check fast-checkarkToArbitrary accepts an ArkType Type and returns a fast-check Arbitrary that generates values matching that schema:
import { arkToArbitrary } from "@ark/fast-check"
import { type } from "arktype"
import { assert, property } from "fast-check"
const User = type({
name: "string",
"age?": "number.integer >= 0"
})
assert(
property(arkToArbitrary(User), value => {
const user = User.assert(value)
return user.age === undefined || user.age >= 0
})
)This is useful when you want property-based tests to cover the same input space that your runtime validators accept.
@ark/fast-check supports common ArkType definitions including:
- primitive domains like
string,number,bigint,boolean,symbolandunknown - unions and literals
- numeric, string, array and date constraints
- arrays, tuples and variadic tuples
- object structures, optional properties and index signatures
- finite aliases and morph inputs
Unsupported schema combinations throw when creating the arbitrary, so test failures point to the unsupported definition before the property runs.