Guide
All Compiled Functions
Every function RunTypes can compile for a type, and the factory that builds it.
RunTypes compiles one function per job, and each has a factory. The full list is at the end of this page.
A function is compiled only where you ask for it. A type you only validate never gets an
encoder.
Calling Every Factory
Each factory takes your type and returns a compiled function. Its options pick which one: createValidateFn<T>() and createValidateFn<T>(undefined, {checkUnknowns: true}) compile two different functions.
// one call per type, at module level
const isUser = createValidateFn<User>();
const isUserStrict = createValidateFn<User>(undefined, {checkUnknowns: true});
const isUserUnionKeys = createValidateFn<User>(undefined, {
checkUnionUnknowns: true,
});
const userErrors = createGetValidationErrorsFn<User>();
const userErrorsStrict = createGetValidationErrorsFn<User>(undefined, {
checkUnknowns: true,
});
const userErrorsUnionKeys = createGetValidationErrorsFn<User>(undefined, {
checkUnionUnknowns: true,
});
const removeUserExtras = createRemoveUnknownKeysFn<User>();
const cleanUser = createFormatTransformFn<User>();
// JSON as a string
const encodeUser = createJsonEncoderFn<User>(undefined, {strategy: 'clone'});
const decodeUser = createJsonDecoderFn<User>(undefined, {strategy: 'clone'});
// JSON as a value inside your own JSON; same strategy on both sides
const prepareUser = createPrepareForJsonFn<User>();
const restoreUser = createRestoreFromJsonFn<User>();
const prepareUserMutate = createPrepareForJsonFn<User>(undefined, {
strategy: 'mutate',
});
const restoreUserMutate = createRestoreFromJsonFn<User>(undefined, {
strategy: 'mutate',
});
const compactUser = createPrepareForJsonFn<User>(undefined, {
strategy: 'compact',
});
const uncompactUser = createRestoreFromJsonFn<User>(undefined, {
strategy: 'compact',
});
// everything else
const userSchema = createJsonSchemaFn<User>();
const mockUser = createMockDataFn<User>();
const userStandardSchema = createStandardSchema<User>();
Asking for Several Functions at Once
A marker names the functions you want. Use it in your own wrapper that needs several functions from one call site.
function userCodec<T>(
fns?: InjectTypeFnArgs<
T,
'validate',
'prepareForJsonClone',
'restoreFromJsonClone'
>
) {
return {
// the key repeated here is the one named in the marker above
isValid: getRTFunction<'validate'>(fns?.[0]),
prepare: getRTFunction<'prepareForJsonClone'>(fns?.[1]),
restore: getRTFunction<'restoreFromJsonClone'>(fns?.[2]),
};
}
// the build injects one handle per name, in the order you listed them
const codec = userCodec<User>();
const user: User = {
id: 42n,
name: 'Ada',
signedUpAt: new Date('2026-01-01T00:00:00Z'),
};
const wire = JSON.stringify(codec.prepare(user));
const back = codec.restore(JSON.parse(wire));
See Compiler Markers for what else a marker can do.
Compiled Functions Reference
Every function RunTypes can compile, with the call that compiles it.
| Call | Compiled Fn | What it does |
|---|---|---|
createFormatTransformFn<T>() | formatTransform | Applies the type's format rules to a value, for example trimming a string or clamping a number. |
createGetValidationErrorsFn<T>() | validationErrors | Returns the list of reasons a value does not match the type, with the path to each one. Takes ValidateOptions. Accepts rejectCircularRefs. |
createGetValidationErrorsFn<T>(undefined, {checkUnknowns: true}) | validationErrorsStrict | Returns the reasons a value does not match, including undeclared properties, in a single walk. Takes ValidateOptions. Accepts rejectCircularRefs. |
createGetValidationErrorsFn<T>(undefined, {checkUnionUnknowns: true}) | validationErrorsUnionKeys | Returns the reasons a value does not match, counting a property the matched union member leaves undeclared. Takes ValidateOptions. Accepts rejectCircularRefs. |
createJsonDecoderFn<T>(undefined, {strategy: 'clone' | 'mutate' | 'compact'}) | jsonDecoder | Turns a JSON string back into a typed value. The strategy decides whether undeclared properties survive. |
createJsonEncoderFn<T>(undefined, {strategy: 'clone' | 'mutate' | 'compact'}) | jsonEncoder | Turns a value into a JSON string. The strategy picks how: build a new value, transform in place, or use the compact positional wire. Accepts rejectCircularRefs. |
createJsonSchemaFn<T>() | jsonSchema | Returns the JSON Schema document describing the type. |
createPrepareForJsonFn<T>(undefined, {strategy: 'compact'}) | compactForJson | Builds a value whose objects are positional arrays, so property names never reach the wire. |
createPrepareForJsonFn<T>() | prepareForJsonClone | Builds a new JSON-safe value from the declared shape, so undeclared properties are dropped. |
createPrepareForJsonFn<T>(undefined, {strategy: 'mutate'}) | prepareForJsonMutate | Turns a value into a JSON-safe value in place. Nothing is allocated and undeclared properties are kept. |
createRemoveUnknownKeysFn<T>() | removeUnknownKeys | Copies a value keeping only the properties the type declares. |
createRemoveUnknownKeysFn<T>(undefined, {sharedValues: 'refuse'}) | removeUnknownKeysRefuse | Copies a value keeping only the declared properties, and refuses a type holding a function or a value it cannot copy. |
createRemoveUnknownKeysFn<T>(undefined, {sharedValues: 'share'}) | removeUnknownKeysShared | Copies a value keeping only the declared properties, sharing a function or a value it cannot copy with the input, as asked. |
createRestoreFromJsonFn<T>(undefined, {strategy: 'compact'}) | compactFromJson | Rebuilds a keyed object from the positional array the compact encoder wrote. |
createRestoreFromJsonFn<T>() | restoreFromJsonClone | Rebuilds the typed shape from a JSON-safe value, so undeclared properties are dropped. |
createRestoreFromJsonFn<T>(undefined, {strategy: 'mutate'}) | restoreFromJsonMutate | Turns a JSON-safe value back into the typed shape in place, keeping undeclared properties. |
createValidateFn<T>() | validate | Answers whether a value matches the type. The cheapest check, and the one every other validator builds on. Takes ValidateOptions. Accepts rejectCircularRefs. |
createValidateFn<T>(undefined, {checkUnknowns: true}) | validateStrict | Answers whether a value matches the type AND carries no undeclared properties, in a single walk. Takes ValidateOptions. Accepts rejectCircularRefs. |
createValidateFn<T>(undefined, {checkUnionUnknowns: true}) | validateUnionKeys | Answers whether a value matches the type AND carries no property the matched union member leaves undeclared. Takes ValidateOptions. Accepts rejectCircularRefs. |