arktype 2.2.10 → 3.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +181 -15
- package/out/attributes.d.ts +50 -14
- package/out/checkers.d.ts +172 -0
- package/out/chunk-2U2AWCI3.js +626 -0
- package/out/chunk-4CUA5XIP.js +7 -0
- package/out/chunk-5U2ZMDNI.js +1566 -0
- package/out/chunk-DLWCO4RV.js +18 -0
- package/out/chunk-E3DZXEZK.js +72 -0
- package/out/chunk-EVCML554.js +47 -0
- package/out/chunk-G45P2CLE.js +63 -0
- package/out/chunk-GPNK5353.js +2529 -0
- package/out/chunk-MLKGABMK.js +9 -0
- package/out/chunk-NRIGTMPM.js +7 -0
- package/out/chunk-PRTMQCHS.js +3 -0
- package/out/chunk-R5G57XC7.js +7 -0
- package/out/chunk-RAZ3TXOE.js +313 -0
- package/out/chunk-SWOOCAHN.js +4 -0
- package/out/chunk-TAHPKDNM.js +3 -0
- package/out/chunk-UETB6YE2.js +14 -0
- package/out/chunk-UK5UGFOX.js +254 -0
- package/out/chunk-VV6YDN2D.js +6118 -0
- package/out/codecs.d.ts +21 -0
- package/out/codecs.js +7 -0
- package/out/config.d.ts +8 -3
- package/out/config.js +2 -3
- package/out/declare.d.ts +17 -3
- package/out/deferred.d.ts +10 -0
- package/out/errors.d.ts +1 -0
- package/out/errors.js +2 -0
- package/out/fn.d.ts +1 -1
- package/out/generic.d.ts +3 -3
- package/out/i18n.d.ts +2 -0
- package/out/i18n.js +2 -0
- package/out/index.d.ts +5 -4
- package/out/index.js +8 -9
- package/out/internal.d.ts +70 -0
- package/out/internal.js +17 -0
- package/out/island.d.ts +2 -0
- package/out/island.js +6 -0
- package/out/islandDependency.d.ts +2 -0
- package/out/islandDependency.js +18 -0
- package/out/keywords/Array.d.ts +2 -2
- package/out/keywords/builtins.d.ts +5 -3
- package/out/keywords/constructors.d.ts +9 -1
- package/out/keywords/functions.d.ts +254 -0
- package/out/keywords/keywords.d.ts +8 -9
- package/out/keywords/number.d.ts +2 -8
- package/out/keywords/phrases.d.ts +245 -0
- package/out/keywords/string.d.ts +14 -113
- package/out/keywords/ts.d.ts +35 -33
- package/out/keywords/ts.js +4 -82
- package/out/locale.d.ts +19 -0
- package/out/locales/de.d.ts +2 -0
- package/out/locales/de.js +2 -0
- package/out/locales/en.d.ts +4 -0
- package/out/locales/en.js +5 -0
- package/out/match.d.ts +6 -6
- package/out/module.d.ts +1 -1
- package/out/mutatesInput.js +3 -0
- package/out/parser/ast/generic.d.ts +6 -3
- package/out/parser/ast/infer.d.ts +1 -1
- package/out/parser/ast/validate.d.ts +11 -6
- package/out/parser/definition.d.ts +68 -7
- package/out/parser/objectLiteral.d.ts +40 -12
- package/out/parser/property.d.ts +3 -5
- package/out/parser/reduce/dynamic.d.ts +16 -7
- package/out/parser/reduce/shared.d.ts +4 -0
- package/out/parser/reduce/static.d.ts +13 -13
- package/out/parser/shift/operand/date.d.ts +0 -5
- package/out/parser/shift/operand/operand.d.ts +2 -1
- package/out/parser/shift/operand/unenclosed.d.ts +9 -6
- package/out/parser/shift/operand/unresolvable.d.ts +68 -0
- package/out/parser/shift/operator/bounds.d.ts +9 -4
- package/out/parser/shift/operator/brand.d.ts +2 -2
- package/out/parser/shift/operator/default.d.ts +2 -2
- package/out/parser/shift/operator/divisor.d.ts +2 -2
- package/out/parser/shift/operator/operator.d.ts +1 -1
- package/out/parser/shift/tokens.d.ts +9 -2
- package/out/parser/string.d.ts +61 -7
- package/out/parser/tupleExpressions.d.ts +7 -3
- package/out/precompiled.d.ts +1 -0
- package/out/precompiled.js +2 -0
- package/out/runtime.d.ts +181 -0
- package/out/runtime.js +4 -0
- package/out/runtimeDevelopment.d.ts +1 -0
- package/out/runtimeDevelopment.js +133 -0
- package/out/runtimeExports.d.ts +1 -0
- package/out/scope.d.ts +40 -11
- package/out/standalone/artifact.d.ts +265 -0
- package/out/standalone/baking.d.ts +201 -0
- package/out/standalone/combinators.d.ts +13 -0
- package/out/standalone/compilers.d.ts +23 -0
- package/out/standalone/creators.d.ts +41 -0
- package/out/standalone/fallbacks.d.ts +48 -0
- package/out/standalone/keys.d.ts +31 -0
- package/out/standalone/modules.d.ts +26 -0
- package/out/standalone/sites.d.ts +52 -0
- package/out/standalone/units.d.ts +31 -0
- package/out/standalone/values.d.ts +60 -0
- package/out/standalone.d.ts +16 -0
- package/out/type.d.ts +45 -6
- package/out/variants/array.d.ts +1 -1
- package/out/variants/base.d.ts +47 -27
- package/out/variants/date.d.ts +1 -1
- package/out/variants/instantiate.d.ts +4 -2
- package/out/variants/number.d.ts +1 -1
- package/out/variants/object.d.ts +17 -12
- package/out/variants/string.d.ts +1 -1
- package/package.json +169 -8
- package/skills/arktype/SKILL.md +278 -43
- package/skills/arktype/references/migrating.md +1296 -0
- package/skills/arktype/references/precompile.md +191 -0
- package/out/attributes.js +0 -3
- package/out/fn.js +0 -58
- package/out/generic.js +0 -37
- package/out/keywords/Array.js +0 -21
- package/out/keywords/FormData.js +0 -40
- package/out/keywords/TypedArray.js +0 -16
- package/out/keywords/builtins.js +0 -11
- package/out/keywords/constructors.js +0 -16
- package/out/keywords/keywords.js +0 -48
- package/out/keywords/number.js +0 -49
- package/out/keywords/string.js +0 -467
- package/out/match.js +0 -95
- package/out/module.js +0 -3
- package/out/nary.js +0 -1
- package/out/parser/ast/bounds.js +0 -1
- package/out/parser/ast/default.js +0 -1
- package/out/parser/ast/divisor.js +0 -1
- package/out/parser/ast/generic.js +0 -1
- package/out/parser/ast/infer.js +0 -1
- package/out/parser/ast/keyof.js +0 -1
- package/out/parser/ast/utils.js +0 -1
- package/out/parser/ast/validate.js +0 -3
- package/out/parser/definition.js +0 -78
- package/out/parser/objectLiteral.js +0 -113
- package/out/parser/property.js +0 -16
- package/out/parser/reduce/dynamic.js +0 -153
- package/out/parser/reduce/shared.js +0 -25
- package/out/parser/reduce/static.js +0 -1
- package/out/parser/shift/operand/date.js +0 -23
- package/out/parser/shift/operand/enclosed.js +0 -82
- package/out/parser/shift/operand/genericArgs.js +0 -16
- package/out/parser/shift/operand/operand.js +0 -16
- package/out/parser/shift/operand/unenclosed.js +0 -59
- package/out/parser/shift/operator/bounds.js +0 -91
- package/out/parser/shift/operator/brand.js +0 -6
- package/out/parser/shift/operator/default.js +0 -29
- package/out/parser/shift/operator/divisor.js +0 -13
- package/out/parser/shift/operator/operator.js +0 -28
- package/out/parser/shift/tokens.js +0 -37
- package/out/parser/string.js +0 -42
- package/out/parser/tupleExpressions.js +0 -75
- package/out/parser/tupleLiteral.js +0 -128
- package/out/scope.js +0 -106
- package/out/type.js +0 -55
- package/out/variants/array.js +0 -1
- package/out/variants/base.js +0 -1
- package/out/variants/date.js +0 -1
- package/out/variants/instantiate.js +0 -1
- package/out/variants/number.js +0 -1
- package/out/variants/object.js +0 -1
- package/out/variants/string.js +0 -1
- /package/out/{declare.js → mutatesInput.d.ts} +0 -0
package/skills/arktype/SKILL.md
CHANGED
|
@@ -1,13 +1,53 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: arktype
|
|
3
|
-
description: Write, review or debug runtime validation with ArkType (the `arktype` package). Use when code imports from "arktype"
|
|
3
|
+
description: Write, review or debug runtime validation in TypeScript with ArkType (the `arktype` package), precompile it with `@ark/aot`, migrate to it, or upgrade it from ArkType 2. Use when code imports from "arktype" or "@ark/aot"; when a TypeScript project needs to validate or parse untrusted data, like API request bodies, route handlers, form data, query params, env vars, JSON, config files, webhooks or LLM tool inputs; when adding a schema or validator; when setting up precompiled validation or fixing an error from `[plugin arktype]` or `arktype-precompile`; when converting schemas from Zod, Valibot, TypeBox, Yup, Joi, Effect Schema or JSON Schema, e.g. "migrate this project from Zod to ArkType"; or when upgrading `arktype` from 2.x to 3.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# ArkType
|
|
7
7
|
|
|
8
8
|
ArkType definitions are TypeScript type syntax, written as strings and objects, that also validate at runtime. If you know the TypeScript type, write that.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
## Migrating a project
|
|
11
|
+
|
|
12
|
+
Migrating from Zod, Valibot, TypeBox, Yup, Joi, Effect Schema or JSON Schema? Read [references/migrating.md](references/migrating.md) first and follow its steps. It has the workflow, the defaults that differ and a section of tables for each library: skip the sections for libraries the project doesn't use. In short:
|
|
13
|
+
|
|
14
|
+
1. Write a config file that sets the old library's defaults, for Zod `configure({ onUndeclaredKey: "delete", exactOptionalPropertyTypes: false })`, and import it first in every file that creates a Type. In a package others install, or a project that already has ArkType Types, don't call `configure()`, which would change those Types too: the reference's step 2 has what to write instead.
|
|
15
|
+
2. Rewrite each schema where it is, under the same name, keeping what it accepts, rejects and returns. Keep each custom message as a `message`.
|
|
16
|
+
3. Keep the code free of casts and `any`.
|
|
17
|
+
4. Before removing the old library, compare the schemas the tests don't cover with their originals on the same inputs, all of them if there's no `test` script.
|
|
18
|
+
5. Swap packages with the project's package manager, then run the `typecheck` and `test` scripts until both pass, without changing what a test expects.
|
|
19
|
+
|
|
20
|
+
If asked to precompile too, set it up last, as [references/precompile.md](references/precompile.md) says.
|
|
21
|
+
|
|
22
|
+
## Upgrading from ArkType 2
|
|
23
|
+
|
|
24
|
+
Follow https://arktype.io/docs/upgrading.md, whose checklist links each breaking change. What most code hits:
|
|
25
|
+
|
|
26
|
+
| ArkType 2 | ArkType 3 |
|
|
27
|
+
| -------------------------------------------------------------- | -------------------------------------------------------------------------- |
|
|
28
|
+
| `out[0]`, `out.length`, `out.map(...)`, `for (const e of out)` | the same on `out.issues` |
|
|
29
|
+
| `error.message`, for text naming its path | `out.summary`, a line per error; `error.message` now leaves the path out |
|
|
30
|
+
| `error.problem`, `{ problem: "..." }` | `error.message`, `{ message: "..." }`, reworded as a whole sentence |
|
|
31
|
+
| `out.flatProblemsByPath`, `out.byPath`, `out.flatByPath` | `flatMessagesByPath(out)`, `byPath(out)`, `flatByPath(out)` from `arktype` |
|
|
32
|
+
| `out.message`, `out.toTraversalError()` | `out.summary`, `new TraversalError(out)` |
|
|
33
|
+
| `error.hasCode("min")`, `error.toString()` | `error.code === "min"`, `error.message`: errors are plain objects |
|
|
34
|
+
| `ctx.errors.add(...)` | `ctx.error(...)` or `ctx.reject(...)` |
|
|
35
|
+
| `configure()` anywhere, the `clone` option | a config file imported before any Type is created; remove `clone` |
|
|
36
|
+
|
|
37
|
+
Then update snapshots of error text: a message no longer says what the value was, like `(was a number)`. Replace adapters written for ArkType 2 as [Integrations](#integrations) says: they pass valid data and fail on the first invalid input.
|
|
38
|
+
|
|
39
|
+
## Precompiling
|
|
40
|
+
|
|
41
|
+
A project whose bundler config uses `@ark/aot` (e.g. `precompile.vite()` from `@ark/aot/unplugin`) constructs every Type at build time and replaces it with a standalone validator, so arktype's parser doesn't ship. To set it up, to add validation to such a project or to fix a build error from it, read [references/precompile.md](references/precompile.md): it has the setup for each bundler, Next.js and test runner, how to write definitions the build accepts, and each build error with its fix. In short:
|
|
42
|
+
|
|
43
|
+
- Define Types from static values, and compose them inside definitions, like `const Admin = User.and({ role: "'admin'" })`. A definition reading a parameter, or a function calling `.or`, `.pick` or another composing method at runtime, fails the build. To reuse a pattern, define a Generic.
|
|
44
|
+
- Define Types in JavaScript or TypeScript modules. A Svelte component's script isn't precompiled, so one importing arktype fails the build: put the Types, and any code checking a result against `type.errors`, in a `.ts` module the component imports.
|
|
45
|
+
- If the project calls `configure()`, name its module as `config` under `precompile` in an `ark.json` beside `package.json`, which the plugin, the test drivers, the CLI and the ESLint rule all read.
|
|
46
|
+
- A build error names the file, line and column, then why, then the fix on its last line. Apply that fix. Don't set `allowUnsafe` or switch to `runtime: "arktype"` to get past one. `npx arktype-precompile --check src` lists every one without bundling.
|
|
47
|
+
- A validator's error messages say what failed but not what the value was, like `name must be a string`.
|
|
48
|
+
- The build works out which introspection members, like a JSON Schema or `expression`, each validator needs from the code reading it, its dependencies' included, so the MCP SDK, the AI SDK and OpenAPI generators get one with nothing to set. Setting one under `members` only overrides that. Code the build can't see, like code outside the bundle reading an entry's export, throws naming the member to set true under `members`.
|
|
49
|
+
|
|
50
|
+
Docs index: https://arktype.io/llms.txt, which links each page's Markdown. Any docs page is available as Markdown by adding `.md` to its URL, e.g. https://arktype.io/docs/objects.md. Every page in one file: https://arktype.io/llms-full.txt.
|
|
11
51
|
|
|
12
52
|
## Define, infer, validate
|
|
13
53
|
|
|
@@ -25,10 +65,13 @@ const User = type({
|
|
|
25
65
|
// the TypeScript type, derived from the definition
|
|
26
66
|
type User = typeof User.infer
|
|
27
67
|
|
|
68
|
+
// e.g. a request body
|
|
69
|
+
declare const body: string
|
|
70
|
+
|
|
28
71
|
const out = User(JSON.parse(body))
|
|
29
72
|
|
|
30
73
|
if (out instanceof type.errors) {
|
|
31
|
-
// every
|
|
74
|
+
// every error, one per line, e.g. `email must be an email address`
|
|
32
75
|
console.error(out.summary)
|
|
33
76
|
} else {
|
|
34
77
|
// out is narrowed to User
|
|
@@ -37,30 +80,62 @@ if (out instanceof type.errors) {
|
|
|
37
80
|
```
|
|
38
81
|
|
|
39
82
|
- Calling a type returns the validated data or an `ArkErrors` instance. It does not throw, so check with `instanceof type.errors` rather than wrapping it in `try`/`catch`.
|
|
40
|
-
- `
|
|
83
|
+
- `ArkErrors` is not an array. Read individual errors from `out.issues`, e.g. `out.issues[0]` or `out.issues.map(e => e.message)`, each with a `path`, `code` and `message`. A `message` leaves out its path, like `must be an email address`.
|
|
84
|
+
- `User.assert(data)` throws a `TraversalError` instead, for places where invalid data is a bug. In a `catch`, check `e instanceof TraversalError` (from `arktype`) and read `e.arkErrors.issues`.
|
|
41
85
|
- Name types in PascalCase (`User`). Name types that transform their input in camelCase (`parseUser`), since they behave like functions.
|
|
42
|
-
- `typeof User.infer` is the output type. `typeof User.inferIn` is the input type, which differs once a type transforms its input.
|
|
86
|
+
- `typeof User.infer` is the output type. `typeof User.inferIn` is the input type, which differs once a type transforms its input or has defaults.
|
|
43
87
|
|
|
44
88
|
## Syntax
|
|
45
89
|
|
|
46
|
-
Strings use TypeScript's operators. Write string literals in single quotes inside the definition.
|
|
47
|
-
|
|
48
|
-
| Want
|
|
49
|
-
|
|
|
50
|
-
| optional key
|
|
51
|
-
| default (objects only)
|
|
52
|
-
|
|
|
53
|
-
|
|
|
54
|
-
|
|
|
55
|
-
|
|
|
56
|
-
|
|
|
57
|
-
|
|
|
58
|
-
|
|
|
59
|
-
|
|
|
60
|
-
|
|
|
61
|
-
|
|
|
62
|
-
|
|
63
|
-
|
|
90
|
+
Strings use TypeScript's operators. Write string literals in single quotes inside the definition. Object types don't go in strings: `"{ a: string }"` doesn't parse, so write objects as objects and name them in a scope to reuse them in a string.
|
|
91
|
+
|
|
92
|
+
| Want | Write |
|
|
93
|
+
| ----------------------- | ------------------------------------------------------------------------ |
|
|
94
|
+
| optional key | `"key?": "string"` |
|
|
95
|
+
| default (objects only) | `count: "number = 0"`, `plan: "'free' \| 'pro' = 'free'"` |
|
|
96
|
+
| object or array default | `tags: "string[] = []"`, or a function: `Tags.default(() => [])` |
|
|
97
|
+
| union | `"string \| number"`, `"'a' \| 'b'"` |
|
|
98
|
+
| array | `"string[]"`, `"(string \| number)[]"` |
|
|
99
|
+
| tuple | `["string", "number"]` |
|
|
100
|
+
| number range | `"number > 0"`, `"0 <= number < 1"`, `"1 <= number.integer <= 100"` |
|
|
101
|
+
| string or array length | `"string > 0"`, `"1 <= string <= 255"`, `"string[] >= 1"` |
|
|
102
|
+
| divisibility | `"number % 2"` |
|
|
103
|
+
| regex | `/^\d+$/` as a RegExp, or `"/^\\d+$/"` in a string |
|
|
104
|
+
| record | `"Record<string, number>"` or `{ "[string]": "number" }` |
|
|
105
|
+
| class instance | `"Date"`, `"Map"`, or `type.instanceOf(MyClass)` |
|
|
106
|
+
| enum from values | `type.enumerated("a", "b")` or `type.valueOf(MyEnum)` |
|
|
107
|
+
| array of a Type | `Item.array()`, `Item.array().atLeastLength(1)` |
|
|
108
|
+
| custom error message | `type("string >= 8").configure({ message: "Use 8 or more characters" })` |
|
|
109
|
+
|
|
110
|
+
A regex with flags, like `/^a$/i`, must be a RegExp. Bounds bind tighter than `|`, so `"string <= 500 | null"` is a string of at most 500 characters, or null.
|
|
111
|
+
|
|
112
|
+
Common keywords: `string.email`, `string.uuid`, `string.url`, `string.ip`, `string.semver`, `string.date.iso`, `string.alphanumeric`, `number.integer`, `number.safe`, `number.epoch`, and `object.json` for JSON data. The full list is at https://arktype.io/docs/keywords.md.
|
|
113
|
+
|
|
114
|
+
## From Zod
|
|
115
|
+
|
|
116
|
+
What a Zod schema becomes. To migrate a project, follow [references/migrating.md](references/migrating.md), which has every API, each library and the defaults that differ.
|
|
117
|
+
|
|
118
|
+
| Zod | ArkType |
|
|
119
|
+
| ----------------------------------------- | ------------------------------------------------------------------------ |
|
|
120
|
+
| `z.object({ ... })` | `type({ ... })`, which keeps undeclared keys unless configured |
|
|
121
|
+
| `z.string().min(1).max(100)` | `"1 <= string <= 100"` |
|
|
122
|
+
| `z.string().email()`, `.url()`, `.uuid()` | `"string.email"`, `"string.url"`, `"string.uuid"` |
|
|
123
|
+
| `z.number().int().positive()` | `"number.integer > 0"` |
|
|
124
|
+
| `z.enum(["a", "b"])` | `"'a' \| 'b'"` |
|
|
125
|
+
| `.optional()` on a key | `"key?": "T \| undefined"`, or `"key?": "T"` with Zod's defaults set |
|
|
126
|
+
| `.nullable()` | `"T \| null"` |
|
|
127
|
+
| `.default(x)` | `key: "T = x"` or `key: T.default(x)` |
|
|
128
|
+
| `z.array(T).min(1)` | `T.array().atLeastLength(1)`, or `"string[] >= 1"` in a string |
|
|
129
|
+
| `z.union([A, B])`, `z.discriminatedUnion` | `A.or(B)` |
|
|
130
|
+
| `.extend({ ... })`, `.pick({ a: true })` | `.merge({ ... })`, `.pick("a")` |
|
|
131
|
+
| `.refine(fn, message)` | `.narrow((v, ctx) => fn(v) \|\| ctx.reject({ message }))` |
|
|
132
|
+
| `.refine(fn, { message, path })` | `ctx.reject({ message, relativePath: path })` |
|
|
133
|
+
| `.min(1, "Name is required")` | `["string >= 1", "@", { message: "Name is required" }]` as a key's value |
|
|
134
|
+
| `.transform(fn)` | `.pipe(fn)` |
|
|
135
|
+
| `z.coerce.number()` | `type("unknown").pipe(Number).to("number")` |
|
|
136
|
+
| `z.infer<typeof T>`, `z.input` | `typeof T.infer`, `typeof T.inferIn` |
|
|
137
|
+
| `T.parse(x)`, `T.safeParse(x)` | `T.assert(x)`, `T(x)` checked with `instanceof type.errors` |
|
|
138
|
+
| `e instanceof ZodError` in a `catch` | `e instanceof TraversalError`, then `e.arkErrors.issues` |
|
|
64
139
|
|
|
65
140
|
## Composing types
|
|
66
141
|
|
|
@@ -83,20 +158,53 @@ const CustomerDraft = Customer.partial()
|
|
|
83
158
|
|
|
84
159
|
Never interpolate a type into a string, as in ``type(`${Address}[]`)``. Use `Address.array()`, `Address.or(...)` and the other chained methods, or a tuple expression like `[Address, "[]"]`.
|
|
85
160
|
|
|
161
|
+
- `.merge()` adds keys and replaces existing ones. `.and()` intersects, and throws when a key's types conflict.
|
|
162
|
+
- `.merge()`, `"..."`, `.pick()`, `.omit()` and `.partial()` drop a `.narrow()` on the object they read, or throw if it also deletes undeclared keys. Keep the keys in a Type of their own, derive from that, and add each `.narrow()` last.
|
|
163
|
+
- To share keys between types, merge a base Type, or `.pick()` them: `User.get("nick")` is the key's Type without its `?` or its default. To reuse a pattern across Types, define a Generic: `const Page = type("<t>", { items: "t[]", total: "number" })`, called as `Page(Item)`. In a Generic's body, `Omit`, `Pick`, `Partial`, `Required` and `Merge` do what the methods of those names do: `const Create = type("<t extends object>", "Omit<t, 'id'>")`.
|
|
164
|
+
- `.as<T>()` is a cast. To infer a narrower type, use `.narrow()` with a type predicate, e.g. `(s): s is \`data-${string}\` => s.startsWith("data-")`.
|
|
165
|
+
- A definition built at runtime goes to `type.raw`, which infers nothing, then gets its type: `type.raw(Object.fromEntries(FLAGS.map(flag => [flag, "boolean"]))).as<Record<Flag, boolean>>()`.
|
|
166
|
+
|
|
167
|
+
A function that takes a Type types its parameter by what it does with it:
|
|
168
|
+
|
|
169
|
+
| The function | Signature |
|
|
170
|
+
| ------------------------------------------- | -------------------------------------------------------------------------------------------------- |
|
|
171
|
+
| validates and returns the data | `<t>(schema: { assert: (data: unknown) => t }, data: unknown): t`, or as a `class Repo<t>`'s field |
|
|
172
|
+
| returns the errors rather than throwing | `<t>(schema: (data: unknown) => t \| ArkErrors, data: unknown)`, checked with `instanceof` |
|
|
173
|
+
| needs the Type itself, with its output type | `<T extends type.Any>(schema: T): T["infer"]` |
|
|
174
|
+
| calls `.and()`, `.or()` or `.array()` on it | `<t extends object>(T: Type<t>) => T.and({ id: "string" })` |
|
|
175
|
+
| puts it in a new definition | `<t>(item: type.Any<t>) => type({ items: item.array(), total: "number" })` |
|
|
176
|
+
| reads its `.props` | `(T: Type<Record<string, unknown>>) => T.props.map(prop => prop.key)` |
|
|
177
|
+
| picks, omits, merges or makes partial | not a function: a Generic, as above |
|
|
178
|
+
| only stores or forwards it | `type.Any`, not `Type<any>` |
|
|
179
|
+
|
|
180
|
+
- On a `type.Any` parameter, a method given a definition, like `T.or("null")` or `T.and({ ... })`, infers `any` with no error, and so does calling it. Annotate the call: `const out: T["infer"] | type.errors = schema(data)`.
|
|
181
|
+
- The `t` of a `type.Any<t>` isn't the output type once a Type has a default or a transform. `T["infer"]` is.
|
|
182
|
+
- A Type exported from a scope isn't a `Type<t>`, so pass it as `type(types.User)`. A Generic takes it as it is.
|
|
183
|
+
- In a precompiled project, keep a helper's body to one expression, or consts and one `return`, and call it with a Type the build knows, like `User`. A helper that passes a generic definition to `type()` needs casts.
|
|
184
|
+
|
|
86
185
|
## Parsing and transforming
|
|
87
186
|
|
|
88
|
-
Keywords ending in `.parse` transform their input. `.to()` validates the parsed result, and `.pipe()` runs your own function.
|
|
187
|
+
Keywords ending in `.parse` transform their input. `.to()` validates the parsed result, and `.pipe()` runs your own function. A morph receives the caller's value itself, not a copy, so return a new value instead of mutating its argument.
|
|
89
188
|
|
|
90
189
|
```ts
|
|
91
190
|
// "8080" -> 8080, then checked as a port
|
|
92
191
|
const parsePort = type("string.integer.parse").to("0 < number <= 65535")
|
|
93
192
|
|
|
94
|
-
// a JSON string -> a validated object
|
|
193
|
+
// a JSON string -> a validated object, e.g. a request body from
|
|
194
|
+
// `await request.text()`, so malformed JSON is an error like any other
|
|
95
195
|
const parsePayload = type("string.json.parse").to({ id: "number.integer" })
|
|
96
196
|
|
|
97
197
|
// any function, after validation
|
|
98
198
|
const parseTrimmed = type("string").pipe(s => s.trim())
|
|
99
199
|
|
|
200
|
+
// form data, as Object.fromEntries(new FormData(form)) gives it: every value
|
|
201
|
+
// is a string, and an unchecked checkbox is absent
|
|
202
|
+
const Signup = type({
|
|
203
|
+
email: "string.email",
|
|
204
|
+
age: type("string.integer.parse").to("13 <= number <= 130"),
|
|
205
|
+
terms: type("'on'").pipe(() => true as const)
|
|
206
|
+
})
|
|
207
|
+
|
|
100
208
|
// env vars arrive as strings, so parse them and give defaults
|
|
101
209
|
const Env = type({
|
|
102
210
|
DATABASE_URL: "string.url",
|
|
@@ -107,9 +215,14 @@ const Env = type({
|
|
|
107
215
|
|
|
108
216
|
Other morph keywords: `string.trim`, `string.lower`, `string.upper`, `string.numeric.parse`, `string.date.parse`, `string.date.iso.parse`, `string.url.parse`.
|
|
109
217
|
|
|
218
|
+
- A `.parse` keyword accepts only strings. When the value may already be parsed, keep both in a union: `"number | string.numeric.parse"`.
|
|
219
|
+
- A check after a transform goes in `.to()`: `type("string.trim").to("string > 0")`.
|
|
220
|
+
- A union can't include a morph whose input overlaps another branch, so `type("unknown").pipe(Number).or("undefined")` throws. Start the morph from the narrowest input, like `"string.numeric.parse | undefined"`, or handle the other case inside the pipe.
|
|
221
|
+
- A default is an input, so a morph's default is what it parses: `flag: type("'true' | 'false'").pipe(s => s === "true").default("false")`.
|
|
222
|
+
|
|
110
223
|
## Custom rules
|
|
111
224
|
|
|
112
|
-
Use `.narrow()` when a rule involves more than one value. Return `true` to accept, or `ctx.reject()` to
|
|
225
|
+
Use `.narrow()` when a rule involves more than one value. Return `true` to accept, or `ctx.reject()` to say what was wrong and where: a `message`, one whole sentence like `"Passwords must match"`, at a `relativePath` from the value being narrowed.
|
|
113
226
|
|
|
114
227
|
```ts
|
|
115
228
|
const Signup = type({
|
|
@@ -119,31 +232,80 @@ const Signup = type({
|
|
|
119
232
|
(data, ctx) =>
|
|
120
233
|
data.password === data.confirmPassword ||
|
|
121
234
|
ctx.reject({
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
path: ["confirmPassword"]
|
|
235
|
+
message: "Passwords must match",
|
|
236
|
+
relativePath: ["confirmPassword"]
|
|
125
237
|
})
|
|
126
238
|
)
|
|
127
239
|
```
|
|
128
240
|
|
|
241
|
+
- Use `relativePath`, not `path`. `path` is from the root of the data, so it names the wrong key once the object is nested or in an array.
|
|
242
|
+
- Always reject with text. Returning `false` reads `must be valid according to an anonymous predicate`.
|
|
243
|
+
- For several errors, call `ctx.error({ message, relativePath })` for each, then return `true`.
|
|
244
|
+
- A narrow on an object runs only once every key is valid, so its error is never reported alongside a key's.
|
|
245
|
+
- A narrow can't give a literal its own text. ArkType calls it on each literal the Type allows, like `false`, `null`, `undefined` or `'a'`, when the Type is defined, and removes those it rejects, so `type("boolean").narrow((v, ctx) => v || ctx.reject({ message: "Accept the terms" }))` reads `must be true`. Write the values allowed, with the message: `type("true").configure({ message: "Accept the terms" })`.
|
|
246
|
+
|
|
247
|
+
## Error messages
|
|
248
|
+
|
|
249
|
+
There are two ways to say what's wrong. Choose by the text you have:
|
|
250
|
+
|
|
251
|
+
| The text is | Write it as | An issue's `message` | Its line of `out.summary` |
|
|
252
|
+
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ----------------------- | ----------------------------- |
|
|
253
|
+
| a whole sentence, like any Zod message: `"Enter a valid email"` | `message`, in `.configure({ message })`, a `"@"` tuple or `ctx.reject({ message })` | `Enter a valid email` | `email: Enter a valid email` |
|
|
254
|
+
| what the value must be: `"a valid email"` | `.describe(text)`, `.configure({ expected: text })`, `ctx.reject(text)`, `ctx.mustBe(text)` | `must be a valid email` | `email must be a valid email` |
|
|
255
|
+
|
|
256
|
+
- A message from Zod, or any sentence a user reads, is always a `message`. Passed as a string to `ctx.reject()`, to `ctx.mustBe()`, to `.describe()`, as `expected` or as a string after `"@"`, it would read `must be Enter a valid email`.
|
|
257
|
+
- An issue's `message` is what a form library, or anything else reading the Type through Standard Schema, shows beside the field. `out.summary`, and the `TraversalError` `.assert()` throws, write a line for each error with its path.
|
|
258
|
+
- A `message` isn't composed into other text. What a Type is `expected` to be is: a union lists it, as in `must be a valid email or null`. So with `| null` or `| undefined`, configure the whole union, as in `["string.email | null", "@", { message }]`: a message on one branch is lost for a value of the wrong type. With `exactOptionalPropertyTypes: false`, an optional or defaulted key's value is such a union, so write `"role?": ["'admin' | 'user' | undefined", "@", { message }]`: a message on an enum, a literal or a boolean alone is never said there.
|
|
259
|
+
- A `message` on `string.date.parse`, `string.url.parse` or `string.json.parse` isn't said for a string that fails to parse. Check, then convert: `type("string.date").pipe(s => new Date(s)).configure({ message })`.
|
|
260
|
+
|
|
261
|
+
In a definition, a tuple with `"@"` configures a value where it's written, as Zod's `.min(1, "Name is required")` does. For a message per check, name the check after it, by its error code (`minLength`, `maxLength`, `pattern`, `min`, `max`, `divisor`), in the tuple or as `.configure()`'s second argument:
|
|
262
|
+
|
|
263
|
+
```ts
|
|
264
|
+
const Invite = type({
|
|
265
|
+
name: ["string > 0", "@", { message: "Name is required" }],
|
|
266
|
+
email: ["string.email", "@", { message: "Enter a valid email" }],
|
|
267
|
+
password: type("string >= 8 & /[0-9]/")
|
|
268
|
+
.configure({ message: "Use 8 or more characters" }, "minLength")
|
|
269
|
+
.configure({ message: "Include a number" }, "pattern")
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
// name: Name is required
|
|
273
|
+
// email: Enter a valid email
|
|
274
|
+
// password: Include a number
|
|
275
|
+
// password: Use 8 or more characters
|
|
276
|
+
const out = Invite({ name: "", email: "x", password: "short" })
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
- A string `message` on a key's whole value, like `name`'s, is what the key says when its value is wrong, `undefined` included, and when the key is missing, so `Invite({})` reads the same for `name` and `email`. It covers Zod's `required_error`.
|
|
280
|
+
- Configure a whole-value message last, after any `.pipe()` or `.to()`: `type("'on'").pipe(() => true).configure({ message: "Accept the terms" })`.
|
|
281
|
+
- A message for one check leaves other errors with ArkType's text, like `password must be a string (was missing)`. To give those their own, name `"domain"` for a wrong type and `"self"` for a missing key.
|
|
282
|
+
- A code names every check of that kind in the Type, nested keys' included, so configure a key's value, not the object around it. An array's length and its elements' are both `minLength`: configure the length on its own Type and intersect, as in `type("unknown[] >= 1").configure({ message: "Add one" }, "minLength").and(Tag.array())`.
|
|
283
|
+
- Configure a whole-value message before per-check ones, since it replaces those configured earlier.
|
|
284
|
+
- After a `.pipe()` or `.to()`, a code doesn't reach the Type the output is checked with, and a whole-value or `"self"` message on the transformed Type replaces the ones inside it. Configure that Type before passing it: `type("string.trim").to(type("string > 0").configure({ message: "Name is required" }))`.
|
|
285
|
+
- Several failed checks report a pattern before a length. For an empty field to say `Email is required` first, as Zod's `.min(1, "...").email("...")` did, leave out the `>= 1` and choose by the value: `.configure({ message: e => (e.data === "" ? "Email is required" : "Enter a valid email") }, "pattern")`. For a length's message to come before a pattern's, write the pattern as a `.narrow()`, which runs once the length passes.
|
|
286
|
+
|
|
287
|
+
To show each message beside its field, group `out.issues` by `issue.path.join(".")`, keeping the first `issue.message` for each key.
|
|
288
|
+
|
|
129
289
|
## Recursive and cyclic types
|
|
130
290
|
|
|
131
|
-
|
|
291
|
+
A type that refers to itself uses `this`. Types that refer to each other go in a scope, where definitions reference each other by name:
|
|
132
292
|
|
|
133
293
|
```ts
|
|
134
|
-
import { scope } from "arktype"
|
|
294
|
+
import { scope, type } from "arktype"
|
|
295
|
+
|
|
296
|
+
const TreeNode = type({ value: "number", children: "this[]" })
|
|
135
297
|
|
|
136
298
|
const types = scope({
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
children: "TreeNode[]"
|
|
140
|
-
}
|
|
299
|
+
User: { name: "string", "posts?": "Post[]" },
|
|
300
|
+
Post: { title: "string", author: "User" }
|
|
141
301
|
}).export()
|
|
142
302
|
|
|
143
|
-
const
|
|
303
|
+
const post = types.Post({ title: "Hello", author: { name: "Ada" } })
|
|
144
304
|
```
|
|
145
305
|
|
|
146
|
-
Don't wrap definitions inside a scope with `type()`. They're resolved within the scope, and `type()` would resolve them globally.
|
|
306
|
+
Don't wrap definitions inside a scope with `type()`. They're resolved within the scope, and `type()` would resolve them globally, so an alias there is `unresolvable`. For a `.narrow()` or a `.pipe()` inside a scope, write a tuple: `["Tag[]", ":", (tags, ctx) => ...]` or `["string", "=>", s => s.trim()]`. For JSON data, use the built-in `"string | number | boolean | null | object.json"` rather than a recursive type of your own.
|
|
307
|
+
|
|
308
|
+
TypeScript can't write an inferred cycle in a `.d.ts`: `tsc` declares it as `any`, or fails with `TS5088`. In a package or project whose declarations are emitted, write them with `npx arktype-precompile --declare` (from `@ark/aot`) instead, which names each cycle for its alias and changes nothing at runtime. See https://arktype.io/docs/precompile/advanced.md.
|
|
147
309
|
|
|
148
310
|
## Extra keys
|
|
149
311
|
|
|
@@ -154,16 +316,89 @@ const Strict = type({ "+": "reject", name: "string" })
|
|
|
154
316
|
const Stripped = type({ "+": "delete", name: "string" })
|
|
155
317
|
```
|
|
156
318
|
|
|
319
|
+
To remove them everywhere, as Zod does, call `configure({ onUndeclaredKey: "delete" })` instead. `.merge()` takes `"+"` from the object merged in, so with per-object `"+"`, write `.merge({ "+": "delete", ... })`; with the global setting, merged objects keep deleting.
|
|
320
|
+
|
|
321
|
+
An object that deletes keys, whether by `"+"` or by `configure`, or that has a default or a transform at a key, transforms its input. A union holding one throws a `ParseError` saying it's indeterminate when another branch could accept the same data: a second object with no literal key like `kind` to tell them apart, or an array, a `Date` or a `Record` beside it. Choose the branch in a `.pipe()` instead:
|
|
322
|
+
|
|
323
|
+
```ts
|
|
324
|
+
const Item = type({ "+": "delete", id: "string" })
|
|
325
|
+
const Items = Item.array()
|
|
326
|
+
|
|
327
|
+
const OneOrMany = type("object").pipe(v =>
|
|
328
|
+
Array.isArray(v) ? Items(v) : Item(v)
|
|
329
|
+
)
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
Where objects delete keys, don't `.narrow()` a union of them at an optional key or before `.or("null")`: its errors become one `union` issue at the union's path, without the failing key's path. Narrow the object holding the key, and reject with `relativePath: ["key"]`.
|
|
333
|
+
|
|
157
334
|
## Integrations
|
|
158
335
|
|
|
159
|
-
- ArkType types are [Standard Schema](https://standardschema.dev), so they work directly with tRPC, oRPC, Hono and other libraries that accept one. react-hook-form takes them through `
|
|
160
|
-
- `
|
|
161
|
-
-
|
|
336
|
+
- ArkType types are [Standard Schema](https://standardschema.dev), so they work directly with tRPC, oRPC, Hono and other libraries that accept one. The MCP TypeScript SDK takes them as a tool's `inputSchema` from its second major version, `@modelcontextprotocol/server`; `@modelcontextprotocol/sdk` accepts only Zod. react-hook-form takes them through `standardSchemaResolver` from `@hookform/resolvers/standard-schema`.
|
|
337
|
+
- For a model's structured output or a tool, the AI SDK takes a Type as `schema` or `inputSchema`. The OpenAI SDK takes one through `standardResponseFormat` and `standardFunction` from `openai/helpers/standard-schema` (6.49 or later, every key required), and the Anthropic SDK through `betaStandardSchemaOutputFormat` and `betaStandardSchemaTool` from `@anthropic-ai/sdk/helpers/beta/standard-schema` (0.121 or later). LangChain's `tool()` type-checks with a Type but throws when the tool runs: give it `schema: T.toJsonSchema()` and call `T.assert(input)` inside.
|
|
338
|
+
- Prefer a library's Standard Schema entry point (`standardSchemaResolver`, Hono's `sValidator` from `@hono/standard-validator`, Superforms' `standard()`) over an adapter written for ArkType 2 (`@hono/arktype-validator`, Superforms' `arktype()`, `arktypeResolver` before `@hookform/resolvers` 5), which fails on invalid input.
|
|
339
|
+
- `User.toJsonSchema()` returns the equivalent JSON Schema. It throws for what JSON Schema can't express, like `Date`, `bigint`, a morph or a `.narrow()`. Handle those with a `fallback` keyed by the error's `code`, e.g. `{ fallback: { date: ctx => ({ ...ctx.base, type: "string", format: "date-time" }) } }`, or pass `{ fallback: annotatingFallback }` (exported from `arktype`) to write them as `x-arktype-*` keywords instead.
|
|
340
|
+
- A model reads what a tool's parameter means from its JSON Schema `description`, which `.describe("the name of a city")` writes. The same text is what the field's errors say it must be. On a Type with checks, `.describe(text, "self")` leaves each check its own error, like `must be at most 7`.
|
|
341
|
+
- Global configuration (error messages, `onUndeclaredKey`, `exactOptionalPropertyTypes`, `numberAllowsInfinity`, and so on) goes through `configure` from `arktype/config`, in its own file, imported first by every file that creates a Type. Calling `configure` after any Type is created, even by reading a keyword like `type.number`, throws unless it changes nothing. See https://arktype.io/docs/configuration.md.
|
|
342
|
+
|
|
343
|
+
## Check your work
|
|
344
|
+
|
|
345
|
+
ArkType reports most mistakes in a definition as a TypeScript error at the definition, and the rest as a `ParseError` thrown when the definition runs. After writing or changing types:
|
|
346
|
+
|
|
347
|
+
1. Run the project's typecheck script, or `npx tsc --noEmit`.
|
|
348
|
+
2. Call each new or changed type on a valid and an invalid value and read what it says, in a scratch file you delete afterwards:
|
|
349
|
+
|
|
350
|
+
```ts
|
|
351
|
+
import { type } from "arktype"
|
|
352
|
+
|
|
353
|
+
const User = type({
|
|
354
|
+
name: ["string > 0", "@", { message: "Name is required" }],
|
|
355
|
+
"age?": "number.integer >= 0"
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
const check = (T: type.Any, valid: unknown, invalid: unknown) => {
|
|
359
|
+
const out = T(valid)
|
|
360
|
+
if (out instanceof type.errors) throw new Error(`rejected: ${out.summary}`)
|
|
361
|
+
const errors = T(invalid)
|
|
362
|
+
if (!(errors instanceof type.errors)) throw new Error("accepted invalid data")
|
|
363
|
+
// read each line: "must be Name is required" means a message was passed as `expected`
|
|
364
|
+
console.log(errors.summary)
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
check(User, { name: "Ada" }, { name: "", age: -1 })
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
3. Run the project's tests.
|
|
371
|
+
|
|
372
|
+
## Errors and their fixes
|
|
373
|
+
|
|
374
|
+
| Error | Fix |
|
|
375
|
+
| --------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
376
|
+
| `'a' is unresolvable`, or `'int' is unresolvable. Did you mean 'number.integer'?` | use the name it suggests, or quote a string literal, `"'a'"`. Keywords have full names: `number.integer`, `string.email`, `Date` |
|
|
377
|
+
| `Type definitions must be strings or objects (was Function)` | a class is `type.instanceOf(MyClass)` or a keyword like `"Date"`, and a predicate is `.narrow(fn)` |
|
|
378
|
+
| `configure() has no option 'clone'` | remove an option 3.0 dropped, like `clone`, or use the name the error suggests for a misspelled one |
|
|
379
|
+
| `problem was removed in 3.0; write message` | rename `problem` to `message` in `.configure()` and `ctx.reject()`, and write it as a whole sentence |
|
|
380
|
+
| `'{' is unresolvable` | write an object as an object, not in a string |
|
|
381
|
+
| `'Type' is unresolvable` | don't interpolate a Type into a string; use `Item.array()`, `Item.or(...)` or `[Item, "[]"]` |
|
|
382
|
+
| `'^\d+$' is unresolvable`, or part of another regex, like `'^'` | put a regex in slashes, `"/^\\d+$/"` |
|
|
383
|
+
| `Defaultable definitions like 'number = 0' are only valid as properties in an object or tuple` | give the default in an object, `{ count: "number = 0" }` |
|
|
384
|
+
| `Only required keys may specify default values` | drop the `?`: a key with a default may be missing |
|
|
385
|
+
| `Argument of type 'never[]' is not assignable to parameter of type '() => ...'` at `.default([])` | an object or array default is a function, `.default(() => [])`, or `"string[] = []"` in a string |
|
|
386
|
+
| `An unordered union of a type including a morph and a type with overlapping input is indeterminate` | narrow the morph's input so no other branch accepts it, as in `"string.numeric.parse \| undefined"`; for objects that delete keys, see [Extra keys](#extra-keys) |
|
|
387
|
+
| `merge operand must be an object (was (In: { ... }) => To<...>)`, or `pick`, `omit`, `partial` | the object has a `.narrow()` and deletes undeclared keys: call the method on the object before its `.narrow()`, then add the narrow |
|
|
388
|
+
| `Intersection at a of string and number results in an unsatisfiable type` | `.and()` found conflicting keys; use `.merge()` to replace them |
|
|
389
|
+
| `Index keys "a", "b" should be specified as named props` | write `Record<"a" \| "b", T>` as `{ a: T, b: T }` |
|
|
390
|
+
| `configure() must be called before any Type is created` | import the module calling `configure()` before any module that creates a Type |
|
|
391
|
+
| `Must use import to load ES Module: .../arktype/out/index.js`, from Jest | arktype ships ES modules only: add `transformIgnorePatterns: ["/node_modules/(?!(\\.pnpm\|arktype\|arkregex\|arksets\|@ark)/)"]` and a transform that reads JavaScript, like the `ts-jest/presets/js-with-ts` preset |
|
|
392
|
+
| an error message reading `must be Enter a valid email` | a sentence was passed as `expected`; pass it as `message` |
|
|
162
393
|
|
|
163
394
|
## Mistakes to avoid
|
|
164
395
|
|
|
165
|
-
-
|
|
166
|
-
- An
|
|
167
|
-
-
|
|
396
|
+
- `number` rejects `NaN`, `Infinity` and `-Infinity`. Allow them in one type with `"number | number.Infinity | number.NegativeInfinity"` (or `number.NaN`), or everywhere with `configure({ numberAllowsInfinity: true })`.
|
|
397
|
+
- An array passes an object whose keys are all optional, and a `Record` its elements fit, like `"Record<string, unknown>"`. To reject it, add `.narrow((o, ctx) => !Array.isArray(o) || ctx.mustBe("an object"))`.
|
|
398
|
+
- Validation is synchronous. An async `.narrow()` is a type error, and an async `.pipe()` puts its promise in the output, where an error it reports after an `await` is lost. Run async checks on the validated data.
|
|
399
|
+
- Don't mutate the argument of a `.pipe()` callback. It's the caller's data; the `clone` option that used to copy it no longer exists. Output shares what a Type didn't change with its input too, where Zod returns copies, so copy a parsed array before sorting or pushing to it.
|
|
400
|
+
- An optional key can be missing, but not present with the value `undefined`, mirroring TypeScript's `exactOptionalPropertyTypes`. An object built like `{ DEBUG: process.env.DEBUG }` holds `undefined` for an unset variable, and a default doesn't replace it either. Write `"key?": "string | undefined"` to allow both, or set `configure({ exactOptionalPropertyTypes: false })` where the project's tsconfig doesn't enable that option.
|
|
401
|
+
- With `"sideEffects": false` in `package.json`, a bundler drops `import "./arktype.config.ts"`, so the bundle runs without the config. List the file: `"sideEffects": ["./src/arktype.config.ts"]`.
|
|
168
402
|
- Don't hand-write a TypeScript interface next to the type. Derive it with `typeof T.infer`, so the two can't drift.
|
|
169
403
|
- An invalid definition is a TypeScript error at the definition itself, with a message saying what's wrong. Fix it there rather than casting it away.
|
|
404
|
+
- An `ArkErrors` may find its issues when first read, so they describe the data as it is then. Read `out.summary` or `out.issues` before the validated data can change, as reactive form state, an Immer draft or an `await` before reporting allow.
|