From 10f7b17d626e3b9b7fd14590e5aa811a583376a0 Mon Sep 17 00:00:00 2001 From: radhityaz <13423125@mahasiswa.itb.ac.id> Date: Wed, 17 Jun 2026 08:01:54 +0700 Subject: [PATCH] docs(fast-check): add package README and integrations docs Document @ark/fast-check usage for property-based testing so adopters can find install steps, arkToArbitrary examples, and supported schema coverage. Closes #1243 Co-authored-by: Cursor --- ark/docs/content/docs/integrations/index.mdx | 36 +++++++++++++++ ark/docs/content/docs/integrations/meta.json | 1 + ark/docs/public/llms.txt | 36 +++++++++++++++ ark/fast-check/README.md | 48 ++++++++++++++++++++ 4 files changed, 121 insertions(+) create mode 100644 ark/fast-check/README.md diff --git a/ark/docs/content/docs/integrations/index.mdx b/ark/docs/content/docs/integrations/index.mdx index a495aa9fb..ef5799a72 100644 --- a/ark/docs/content/docs/integrations/index.mdx +++ b/ark/docs/content/docs/integrations/index.mdx @@ -64,6 +64,42 @@ const User = jsonSchemaToType({ See the [`@ark/json-schema` README](https://github.com/arktypeio/arktype/tree/main/ark/json-schema) for more details and limitations. +### fast-check + +The `@ark/fast-check` package converts ArkType schemas to [`fast-check`](https://fast-check.dev) arbitraries for property-based testing: + +```sh +pnpm add @ark/fast-check fast-check +``` + +Import `arkToArbitrary` from `@ark/fast-check`, then pass any `Type` to your `fast-check` properties: + +```ts +// @noErrors +import { type } from "arktype" + +declare const arkToArbitrary: (schema: type.Any) => unknown +declare const assert: (property: unknown) => void +declare const property: ( + arbitrary: unknown, + predicate: (value: unknown) => boolean +) => unknown + +const User = type({ + name: "string", + "age?": "number.integer >= 0" +}) + +assert( + property(arkToArbitrary(User), value => { + User.assert(value) + return true + }) +) +``` + +This lets tests generate inputs from the same schema they validate against. See the [`@ark/fast-check` README](https://github.com/arktypeio/arktype/tree/main/ark/fast-check) for supported schemas and limitations. + ### tRPC ArkType can easily be used with tRPC: diff --git a/ark/docs/content/docs/integrations/meta.json b/ark/docs/content/docs/integrations/meta.json index a0a2fa844..d6d26abf3 100644 --- a/ark/docs/content/docs/integrations/meta.json +++ b/ark/docs/content/docs/integrations/meta.json @@ -3,6 +3,7 @@ "pages": [ "[Standard Schema](/docs/integrations#standard-schema)", "[JSON Schema](/docs/integrations#json-schema)", + "[fast-check](/docs/integrations#fast-check)", "[tRPC](/docs/integrations#trpc)", "[drizzle](/docs/integrations#drizzle)", "[react-hook-form](/docs/integrations#react-hook-form)", diff --git a/ark/docs/public/llms.txt b/ark/docs/public/llms.txt index eb8914f22..c3815d7c2 100644 --- a/ark/docs/public/llms.txt +++ b/ark/docs/public/llms.txt @@ -2796,6 +2796,42 @@ const User = jsonSchemaToType({ See the [`@ark/json-schema` README](https://github.com/arktypeio/arktype/tree/main/ark/json-schema) for more details and limitations. +### fast-check + +The `@ark/fast-check` package converts ArkType schemas to [`fast-check`](https://fast-check.dev) arbitraries for property-based testing: + +```sh +pnpm add @ark/fast-check fast-check +``` + +Import `arkToArbitrary` from `@ark/fast-check`, then pass any `Type` to your `fast-check` properties: + +```ts +// @noErrors +import { type } from "arktype" + +declare const arkToArbitrary: (schema: type.Any) => unknown +declare const assert: (property: unknown) => void +declare const property: ( + arbitrary: unknown, + predicate: (value: unknown) => boolean +) => unknown + +const User = type({ + name: "string", + "age?": "number.integer >= 0" +}) + +assert( + property(arkToArbitrary(User), value => { + User.assert(value) + return true + }) +) +``` + +This lets tests generate inputs from the same schema they validate against. See the [`@ark/fast-check` README](https://github.com/arktypeio/arktype/tree/main/ark/fast-check) for supported schemas and limitations. + ### tRPC ArkType can easily be used with tRPC: diff --git a/ark/fast-check/README.md b/ark/fast-check/README.md new file mode 100644 index 000000000..3723a25a0 --- /dev/null +++ b/ark/fast-check/README.md @@ -0,0 +1,48 @@ +# @ark/fast-check + +Generate [`fast-check`](https://fast-check.dev) arbitraries from ArkType schemas. + +## Install + +Install it alongside `fast-check`: + +```sh +pnpm add arktype @ark/fast-check fast-check +``` + +## Usage + +`arkToArbitrary` accepts an ArkType `Type` and returns a `fast-check` `Arbitrary` that generates values matching that schema: + +```ts +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. + +## Supported Schemas + +`@ark/fast-check` supports common ArkType definitions including: + +- primitive domains like `string`, `number`, `bigint`, `boolean`, `symbol` and `unknown` +- 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.