misc module
clone() functions
undefined
export namespace misc {
export function clone<T>(input: T): T;
export function assertClone<T>(input: T | unknown): Resolved<T>;
export function isClone<T>(input: T | unknown): Resolved<T> | null;
export function validateClone<T>(input: T | unknown): IValidation<Resolved<T>>;
export function createClone<T>(): (input: T) => Resolved<T>;
export function createAssertClone<T>(): (input: T | unknown) => Resolved<T>;
export function createIsClone<T>(): (input: T | unknown) => Resolved<T> | null;
export function createValidateClone<T>(): (
input: T | unknown
) => IValidation<Resolved<T>>;
}undefined
/**
* Error thrown when type assertion fails.
*
* Thrown by {@link assert}, {@link assertGuard}, and other assert-family
* functions when input doesn't match expected type `T`. Contains detailed
* information about the first assertion failure:
*
* - `method`: Which typia function threw (e.g., `"typia.assert"`)
* - `path`: Property path where error occurred (e.g., `"input.user.age"`)
* - `expected`: Expected type string (e.g., `"number & ExclusiveMinimum<19>"`)
* - `value`: Actual value that failed validation
*
* @template T Expected type (for type safety)
*/
export class TypeGuardError<T = any> extends Error {
/**
* Name of the typia method that threw this error.
*
* E.g., `"typia.assert"`, `"typia.assertEquals"`, `"typia.assertGuard"`.
*/
public readonly method: string;
/**
* Property path where assertion failed.
*
* Uses dot notation for nested properties. `undefined` if error occurred at
* root level.
*
* E.g., `"input.age"`, `"input.profile.email"`, `"input[0].name"`.
*/
public readonly path: string | undefined;
/**
* String representation of expected type.
*
* E.g., `"string"`, `"number & ExclusiveMinimum<19>"`, `"{ name: string; age:
* number }"`.
*/
public readonly expected: string;
/**
* Actual value that failed assertion.
*
* The raw value at the error path, useful for debugging.
*/
public readonly value: unknown;
/**
* Optional human-readable error description.
*
* Primarily for AI agent libraries or custom validation scenarios needing
* additional context. Standard assertions rely on `path`, `expected`, and
* `value` for error reporting.
*/
public readonly description?: string | undefined;
/**
* Phantom property for TypeScript type safety.
*
* Not used at runtime—exists only to preserve generic type `T` in the type
* system. Always `undefined`.
*
* @internal
*/
protected readonly fake_expected_typed_value_?: T | undefined;
/**
* Creates a new TypeGuardError instance.
*
* @param props Error properties
*/
public constructor(props: TypeGuardError.IProps) {
// MESSAGE CONSTRUCTION
// Use custom message if provided, otherwise generate default format
super(
props.message ||
`Error on ${props.method}(): invalid type${
props.path ? ` on ${props.path}` : ""
}, expect to be ${props.expected}`,
);
// INHERITANCE POLYFILL
// Set up prototype for compatibility across different JavaScript environments
const proto = new.target.prototype;
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
else (this as any).__proto__ = proto;
// ASSIGN MEMBERS
this.method = props.method;
this.path = props.path;
this.expected = props.expected;
this.value = props.value;
if (props.description || props.value === undefined)
this.description =
props.description ??
[
"The value at this path is `undefined`.",
"",
`Please fill the \`${props.expected}\` typed value next time.`,
].join("\n");
}
}
export namespace TypeGuardError {
/** Properties for constructing a TypeGuardError. */
export interface IProps {
/**
* Name of the typia method that threw the error.
*
* E.g., `"typia.assert"`, `"typia.assertEquals"`.
*/
method: string;
/**
* Property path where assertion failed (optional).
*
* E.g., `"input.age"`, `"input.profile.email"`.
*/
path?: undefined | string;
/**
* String representation of expected type.
*
* E.g., `"string"`, `"number & ExclusiveMinimum<19>"`.
*/
expected: string;
/** Actual value that failed assertion. */
value: unknown;
/**
* Optional human-readable error description.
*
* For AI agent libraries or custom validation needing additional context.
*/
description?: string;
/**
* Custom error message (optional).
*
* If not provided, a default message is generated from other properties.
*/
message?: undefined | string;
}
}undefined
/**
* Validation result type with detailed error information.
*
* `IValidation<T>` is the return type of `typia.validate<T>()` and related
* validation functions. Unlike `typia.is<T>()` which returns a boolean, or
* `typia.assert<T>()` which throws exceptions, `typia.validate<T>()` returns
* this structured result with full error details.
*
* Check the {@link IValidation.success | success} discriminator:
*
* - `true` → {@link IValidation.ISuccess} with validated
* {@link IValidation.ISuccess.data | data}
* - `false` → {@link IValidation.IFailure} with
* {@link IValidation.IFailure.errors | errors} array
*
* This is the recommended validation function when you need to report
* validation errors to users or log them for debugging.
*
* @author Jeongho Nam - https://github.com/samchon
* @example
* const result = typia.validate<User>(input);
* if (result.success) {
* return result.data; // User type
* } else {
* result.errors.forEach((e) => console.log(e.path, e.expected));
* }
*
* @template T The expected type after successful validation
*/
export type IValidation<T = unknown> =
| IValidation.ISuccess<T>
| IValidation.IFailure;
export namespace IValidation {
/**
* Successful validation result.
*
* Indicates the input matches the expected type. The validated data is
* available in {@link data} with full type information.
*
* @template T The validated type
*/
export interface ISuccess<T = unknown> {
/**
* Success discriminator.
*
* Always `true` for successful validations. Use this to narrow the type
* before accessing {@link data}.
*/
success: true;
/**
* The validated data with correct type.
*
* The original input after successful validation. TypeScript will narrow
* this to type `T` when {@link success} is `true`.
*/
data: T;
}
/**
* Failed validation result with error details.
*
* Indicates the input did not match the expected type. Contains the original
* data and an array of all validation errors found.
*/
export interface IFailure {
/**
* Success discriminator.
*
* Always `false` for failed validations. Use this to narrow the type before
* accessing {@link errors}.
*/
success: false;
/**
* The original input that failed validation.
*
* Preserved as `unknown` type since it didn't match the expected type.
* Useful for debugging or logging the actual value.
*/
data: unknown;
/**
* Array of validation errors.
*
* Contains one entry for each validation failure found. Multiple errors may
* exist if the input has multiple type mismatches.
*/
errors: IError[];
}
/**
* Detailed information about a single validation error.
*
* Describes exactly what went wrong during validation, including the
* location, expected type, and actual value.
*/
export interface IError {
/**
* Property path to the error location.
*
* A dot-notation path from the root input to the failing property. Uses
* `$input` as the root. Example: `"$input.user.email"` or
* `"$input.items[0].price"`.
*/
path: string;
/**
* Expected type expression.
*
* A human-readable description of what type was expected at this location.
* Examples: `"string"`, `"number & ExclusiveMinimum<0>"`, `"(\"active\" |
* \"inactive\")"`.
*/
expected: string;
/**
* The actual value that failed validation.
*
* The value found at the error path. May be `undefined` if the property was
* missing. Useful for debugging type mismatches.
*/
value: unknown;
/**
* Human-readable error description.
*
* Optional additional context about the validation failure, such as
* constraint violations or custom error messages.
*/
description?: string;
}
}undefined
import { Equal } from "./internal/Equal";
import { IsTuple } from "./internal/IsTuple";
import { NativeClass } from "./internal/NativeClass";
import { ValueOf } from "./internal/ValueOf";
/**
* Converts a type to its resolved form by erasing all methods.
*
* `Resolved<T>` transforms classes to plain objects, extracts primitive values
* from boxed types (Boolean→boolean, Number→number, String→string), and
* recursively processes nested structures. Native classes (Date, Set, Map,
* etc.) are preserved unchanged.
*
* @author Jeongho Nam - https://github.com/samchon
* @author Kyungsu Kang - https://github.com/kakasoo
* @template T Target type to resolve
*/
export type Resolved<T> =
Equal<T, ResolvedMain<T>> extends true ? T : ResolvedMain<T>;
type ResolvedMain<T> = T extends [never]
? never // (special trick for jsonable | null) type
: ValueOf<T> extends boolean | number | bigint | string
? ValueOf<T>
: T extends Function
? never
: T extends object
? ResolvedObject<T>
: ValueOf<T>;
type ResolvedObject<T extends object> =
T extends Array<infer U>
? IsTuple<T> extends true
? ResolvedTuple<T>
: ResolvedMain<U>[]
: T extends Set<infer U>
? Set<ResolvedMain<U>>
: T extends Map<infer K, infer V>
? Map<ResolvedMain<K>, ResolvedMain<V>>
: T extends WeakSet<any> | WeakMap<any, any>
? never
: T extends NativeClass
? T
: {
[P in keyof T]: ResolvedMain<T[P]>;
};
type ResolvedTuple<T extends readonly any[]> = T extends []
? []
: T extends [infer F]
? [ResolvedMain<F>]
: T extends [infer F, ...infer Rest extends readonly any[]]
? [ResolvedMain<F>, ...ResolvedTuple<Rest>]
: T extends [(infer F)?]
? [ResolvedMain<F>?]
: T extends [(infer F)?, ...infer Rest extends readonly any[]]
? [ResolvedMain<F>?, ...ResolvedTuple<Rest>]
: [];Deep copy functions.
When you want to copy an instance, just call typia.misc.clone() function. It would perform deep copy including nested objects, so you can get a new instance with same values. Also, if you want type safe deep copy function, you can use typia.misc.isClone(), typia.misc.assertClone() or typia.misc.validateClone() functions instead.
typia.misc.assertClone():typia.assert<T>()+typia.misc.clone<T>()typia.misc.isClone():typia.is<T>()+typia.misc.clone<T>()typia.misc.validateClone():typia.validate<T>()+typia.misc.clone<T>()
TypeScript Source Code
import typia from "typia";
const department: IDepartment = typia.random<IDepartment>();
const cloned: IDepartment = typia.misc.assertClone(department);
console.log(cloned);
interface IDepartment {
/** @format uuid */
id: string;
/** @minLength 3 */
name: string;
/** @type int */
limit: number;
clerks: IClerk[];
}
interface IClerk {
name: string;
/**
* @exclusiveMinimum 19
* @maximum 100
*/
age: number;
authority: number;
/** @format date */
joined_at: string;
}Compiled JavaScript File
import typia from "typia";
import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard";
import * as __typia_transform__randomArray from "typia/lib/internal/_randomArray";
import * as __typia_transform__randomFormatDate from "typia/lib/internal/_randomFormatDate";
import * as __typia_transform__randomFormatUuid from "typia/lib/internal/_randomFormatUuid";
import * as __typia_transform__randomInteger from "typia/lib/internal/_randomInteger";
import * as __typia_transform__randomNumber from "typia/lib/internal/_randomNumber";
import * as __typia_transform__randomString from "typia/lib/internal/_randomString";
const department = (() => {
const _ro0 = (_recursive = false, _depth = 0) => ({
id: (
_generator?.uuid ?? __typia_transform__randomFormatUuid._randomFormatUuid
)(),
name: (_generator?.string ?? __typia_transform__randomString._randomString)(
{
type: "string",
minLength: 3,
},
),
limit: (
_generator?.integer ?? __typia_transform__randomInteger._randomInteger
)({
type: "integer",
}),
clerks: (_generator?.array ?? __typia_transform__randomArray._randomArray)({
type: "array",
element: () => _ro1(_recursive, _recursive ? 1 + _depth : _depth),
}),
});
const _ro1 = (_recursive = false, _depth = 0) => ({
name: (_generator?.string ?? __typia_transform__randomString._randomString)(
{
type: "string",
},
),
age: (_generator?.number ?? __typia_transform__randomNumber._randomNumber)({
type: "number",
exclusiveMinimum: 19,
maximum: 100,
}),
authority: (
_generator?.number ?? __typia_transform__randomNumber._randomNumber
)({
type: "number",
}),
joined_at: (
_generator?.date ?? __typia_transform__randomFormatDate._randomFormatDate
)(),
});
let _generator;
return (generator) => {
_generator = generator;
return _ro0();
};
})()();
const cloned = (() => {
const _cp0 = (input) => input.map((elem) => _co1(elem));
const _io0 = (input) =>
"string" === typeof input.id &&
/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(
input.id,
) &&
"string" === typeof input.name &&
3 <= input.name.length &&
"number" === typeof input.limit &&
Math.floor(input.limit) === input.limit &&
-2147483648 <= input.limit &&
input.limit <= 2147483647 &&
Array.isArray(input.clerks) &&
input.clerks.every(
(elem) => "object" === typeof elem && null !== elem && _io1(elem),
);
const _io1 = (input) =>
"string" === typeof input.name &&
"number" === typeof input.age &&
19 < input.age &&
input.age <= 100 &&
"number" === typeof input.authority &&
"string" === typeof input.joined_at &&
/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.test(input.joined_at);
const _ao0 = (input, _path, _exceptionable = true) =>
(("string" === typeof input.id &&
(/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(
input.id,
) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertClone",
path: _path + ".id",
expected: 'string & Format<"uuid">',
value: input.id,
},
_errorFactory,
))) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertClone",
path: _path + ".id",
expected: '(string & Format<"uuid">)',
value: input.id,
},
_errorFactory,
)) &&
(("string" === typeof input.name &&
(3 <= input.name.length ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertClone",
path: _path + ".name",
expected: "string & MinLength<3>",
value: input.name,
},
_errorFactory,
))) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertClone",
path: _path + ".name",
expected: "(string & MinLength<3>)",
value: input.name,
},
_errorFactory,
)) &&
(("number" === typeof input.limit &&
((Math.floor(input.limit) === input.limit &&
-2147483648 <= input.limit &&
input.limit <= 2147483647) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertClone",
path: _path + ".limit",
expected: 'number & Type<"int32">',
value: input.limit,
},
_errorFactory,
))) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertClone",
path: _path + ".limit",
expected: '(number & Type<"int32">)',
value: input.limit,
},
_errorFactory,
)) &&
(((Array.isArray(input.clerks) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertClone",
path: _path + ".clerks",
expected: "Array<IClerk>",
value: input.clerks,
},
_errorFactory,
)) &&
input.clerks.every(
(elem, _index2) =>
((("object" === typeof elem && null !== elem) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertClone",
path: _path + ".clerks[" + _index2 + "]",
expected: "IClerk",
value: elem,
},
_errorFactory,
)) &&
_ao1(
elem,
_path + ".clerks[" + _index2 + "]",
true && _exceptionable,
)) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertClone",
path: _path + ".clerks[" + _index2 + "]",
expected: "IClerk",
value: elem,
},
_errorFactory,
),
)) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertClone",
path: _path + ".clerks",
expected: "Array<IClerk>",
value: input.clerks,
},
_errorFactory,
));
const _ao1 = (input, _path, _exceptionable = true) =>
("string" === typeof input.name ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertClone",
path: _path + ".name",
expected: "string",
value: input.name,
},
_errorFactory,
)) &&
(("number" === typeof input.age &&
(19 < input.age ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertClone",
path: _path + ".age",
expected: "number & ExclusiveMinimum<19>",
value: input.age,
},
_errorFactory,
)) &&
(input.age <= 100 ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertClone",
path: _path + ".age",
expected: "number & Maximum<100>",
value: input.age,
},
_errorFactory,
))) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertClone",
path: _path + ".age",
expected: "(number & ExclusiveMinimum<19> & Maximum<100>)",
value: input.age,
},
_errorFactory,
)) &&
("number" === typeof input.authority ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertClone",
path: _path + ".authority",
expected: "number",
value: input.authority,
},
_errorFactory,
)) &&
(("string" === typeof input.joined_at &&
(/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.test(
input.joined_at,
) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertClone",
path: _path + ".joined_at",
expected: 'string & Format<"date">',
value: input.joined_at,
},
_errorFactory,
))) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertClone",
path: _path + ".joined_at",
expected: '(string & Format<"date">)',
value: input.joined_at,
},
_errorFactory,
));
const _co0 = (input) => ({
id: input.id,
name: input.name,
limit: input.limit,
clerks: _cp0(input.clerks),
});
const _co1 = (input) => ({
name: input.name,
age: input.age,
authority: input.authority,
joined_at: input.joined_at,
});
const __is = (input) =>
"object" === typeof input && null !== input && _io0(input);
let _errorFactory;
const __assert = (input, errorFactory) => {
if (false === __is(input)) {
_errorFactory = errorFactory;
((input, _path, _exceptionable = true) =>
((("object" === typeof input && null !== input) ||
__typia_transform__assertGuard._assertGuard(
true,
{
method: "typia.misc.assertClone",
path: _path + "",
expected: "IDepartment",
value: input,
},
_errorFactory,
)) &&
_ao0(input, _path + "", true)) ||
__typia_transform__assertGuard._assertGuard(
true,
{
method: "typia.misc.assertClone",
path: _path + "",
expected: "IDepartment",
value: input,
},
_errorFactory,
))(input, "$input", true);
}
return input;
};
const __clone = (input) => _co0(input);
return (input, errorFactory) => __clone(__assert(input, errorFactory));
})()(department);
console.log(cloned);prune() functions
undefined
export function prune<T>(input: T): void;
export function assertPrune<T>(input: T | unknown): T;
export function isPrune<T>(input: T | unknown): T | null;
export function validatePrune<T>(input: T | unknown): IValidation<T>;
export function createPrune<T>(): (input: T) => void;
export function createAssertPrune<T>(): (input: T | unknown) => T;
export function createIsPrune<T>(): (input: T | unknown) => T | null;
export function createValidatePrune<T>(): (input: T | unknown) => IValidation<T>;undefined
/**
* Error thrown when type assertion fails.
*
* Thrown by {@link assert}, {@link assertGuard}, and other assert-family
* functions when input doesn't match expected type `T`. Contains detailed
* information about the first assertion failure:
*
* - `method`: Which typia function threw (e.g., `"typia.assert"`)
* - `path`: Property path where error occurred (e.g., `"input.user.age"`)
* - `expected`: Expected type string (e.g., `"number & ExclusiveMinimum<19>"`)
* - `value`: Actual value that failed validation
*
* @template T Expected type (for type safety)
*/
export class TypeGuardError<T = any> extends Error {
/**
* Name of the typia method that threw this error.
*
* E.g., `"typia.assert"`, `"typia.assertEquals"`, `"typia.assertGuard"`.
*/
public readonly method: string;
/**
* Property path where assertion failed.
*
* Uses dot notation for nested properties. `undefined` if error occurred at
* root level.
*
* E.g., `"input.age"`, `"input.profile.email"`, `"input[0].name"`.
*/
public readonly path: string | undefined;
/**
* String representation of expected type.
*
* E.g., `"string"`, `"number & ExclusiveMinimum<19>"`, `"{ name: string; age:
* number }"`.
*/
public readonly expected: string;
/**
* Actual value that failed assertion.
*
* The raw value at the error path, useful for debugging.
*/
public readonly value: unknown;
/**
* Optional human-readable error description.
*
* Primarily for AI agent libraries or custom validation scenarios needing
* additional context. Standard assertions rely on `path`, `expected`, and
* `value` for error reporting.
*/
public readonly description?: string | undefined;
/**
* Phantom property for TypeScript type safety.
*
* Not used at runtime—exists only to preserve generic type `T` in the type
* system. Always `undefined`.
*
* @internal
*/
protected readonly fake_expected_typed_value_?: T | undefined;
/**
* Creates a new TypeGuardError instance.
*
* @param props Error properties
*/
public constructor(props: TypeGuardError.IProps) {
// MESSAGE CONSTRUCTION
// Use custom message if provided, otherwise generate default format
super(
props.message ||
`Error on ${props.method}(): invalid type${
props.path ? ` on ${props.path}` : ""
}, expect to be ${props.expected}`,
);
// INHERITANCE POLYFILL
// Set up prototype for compatibility across different JavaScript environments
const proto = new.target.prototype;
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
else (this as any).__proto__ = proto;
// ASSIGN MEMBERS
this.method = props.method;
this.path = props.path;
this.expected = props.expected;
this.value = props.value;
if (props.description || props.value === undefined)
this.description =
props.description ??
[
"The value at this path is `undefined`.",
"",
`Please fill the \`${props.expected}\` typed value next time.`,
].join("\n");
}
}
export namespace TypeGuardError {
/** Properties for constructing a TypeGuardError. */
export interface IProps {
/**
* Name of the typia method that threw the error.
*
* E.g., `"typia.assert"`, `"typia.assertEquals"`.
*/
method: string;
/**
* Property path where assertion failed (optional).
*
* E.g., `"input.age"`, `"input.profile.email"`.
*/
path?: undefined | string;
/**
* String representation of expected type.
*
* E.g., `"string"`, `"number & ExclusiveMinimum<19>"`.
*/
expected: string;
/** Actual value that failed assertion. */
value: unknown;
/**
* Optional human-readable error description.
*
* For AI agent libraries or custom validation needing additional context.
*/
description?: string;
/**
* Custom error message (optional).
*
* If not provided, a default message is generated from other properties.
*/
message?: undefined | string;
}
}undefined
/**
* Validation result type with detailed error information.
*
* `IValidation<T>` is the return type of `typia.validate<T>()` and related
* validation functions. Unlike `typia.is<T>()` which returns a boolean, or
* `typia.assert<T>()` which throws exceptions, `typia.validate<T>()` returns
* this structured result with full error details.
*
* Check the {@link IValidation.success | success} discriminator:
*
* - `true` → {@link IValidation.ISuccess} with validated
* {@link IValidation.ISuccess.data | data}
* - `false` → {@link IValidation.IFailure} with
* {@link IValidation.IFailure.errors | errors} array
*
* This is the recommended validation function when you need to report
* validation errors to users or log them for debugging.
*
* @author Jeongho Nam - https://github.com/samchon
* @example
* const result = typia.validate<User>(input);
* if (result.success) {
* return result.data; // User type
* } else {
* result.errors.forEach((e) => console.log(e.path, e.expected));
* }
*
* @template T The expected type after successful validation
*/
export type IValidation<T = unknown> =
| IValidation.ISuccess<T>
| IValidation.IFailure;
export namespace IValidation {
/**
* Successful validation result.
*
* Indicates the input matches the expected type. The validated data is
* available in {@link data} with full type information.
*
* @template T The validated type
*/
export interface ISuccess<T = unknown> {
/**
* Success discriminator.
*
* Always `true` for successful validations. Use this to narrow the type
* before accessing {@link data}.
*/
success: true;
/**
* The validated data with correct type.
*
* The original input after successful validation. TypeScript will narrow
* this to type `T` when {@link success} is `true`.
*/
data: T;
}
/**
* Failed validation result with error details.
*
* Indicates the input did not match the expected type. Contains the original
* data and an array of all validation errors found.
*/
export interface IFailure {
/**
* Success discriminator.
*
* Always `false` for failed validations. Use this to narrow the type before
* accessing {@link errors}.
*/
success: false;
/**
* The original input that failed validation.
*
* Preserved as `unknown` type since it didn't match the expected type.
* Useful for debugging or logging the actual value.
*/
data: unknown;
/**
* Array of validation errors.
*
* Contains one entry for each validation failure found. Multiple errors may
* exist if the input has multiple type mismatches.
*/
errors: IError[];
}
/**
* Detailed information about a single validation error.
*
* Describes exactly what went wrong during validation, including the
* location, expected type, and actual value.
*/
export interface IError {
/**
* Property path to the error location.
*
* A dot-notation path from the root input to the failing property. Uses
* `$input` as the root. Example: `"$input.user.email"` or
* `"$input.items[0].price"`.
*/
path: string;
/**
* Expected type expression.
*
* A human-readable description of what type was expected at this location.
* Examples: `"string"`, `"number & ExclusiveMinimum<0>"`, `"(\"active\" |
* \"inactive\")"`.
*/
expected: string;
/**
* The actual value that failed validation.
*
* The value found at the error path. May be `undefined` if the property was
* missing. Useful for debugging type mismatches.
*/
value: unknown;
/**
* Human-readable error description.
*
* Optional additional context about the validation failure, such as
* constraint violations or custom error messages.
*/
description?: string;
}
}Deep prune functions.
When you want to remove every extra properties that are not defined in the type including nested objects, you can use typia.misc.prune<T>() function. Also, if you want to perform type safe pruning, you can use typia.misc.isPrune<T>(), typia.misc.assertPrune<T>() or typia.misc.validatePrune<T>() functions instead.
typia.misc.isPrune():typia.is<T>()+typia.misc.prune<T>()typia.misc.assertPrune():typia.assert<T>()+typia.misc.prune<T>()typia.misc.validatePrune():typia.validate<T>()+typia.misc.prune<T>()
TypeScript Source Code
import typia from "typia";
const department: IDepartment = typia.random<IDepartment>();
const pruned: IDepartment = typia.misc.assertPrune(department);
console.log(pruned);
interface IDepartment {
/** @format uuid */
id: string;
/** @minLength 3 */
name: string;
/** @type int */
limit: number;
clerks: IClerk[];
}
interface IClerk {
name: string;
/**
* @exclusiveMinimum 19
* @maximum 100
*/
age: number;
authority: number;
/** @format date */
joined_at: string;
}Compiled JavaScript File
import typia from "typia";
import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard";
import * as __typia_transform__randomArray from "typia/lib/internal/_randomArray";
import * as __typia_transform__randomFormatDate from "typia/lib/internal/_randomFormatDate";
import * as __typia_transform__randomFormatUuid from "typia/lib/internal/_randomFormatUuid";
import * as __typia_transform__randomInteger from "typia/lib/internal/_randomInteger";
import * as __typia_transform__randomNumber from "typia/lib/internal/_randomNumber";
import * as __typia_transform__randomString from "typia/lib/internal/_randomString";
const department = (() => {
const _ro0 = (_recursive = false, _depth = 0) => ({
id: (
_generator?.uuid ?? __typia_transform__randomFormatUuid._randomFormatUuid
)(),
name: (_generator?.string ?? __typia_transform__randomString._randomString)(
{
type: "string",
minLength: 3,
},
),
limit: (
_generator?.integer ?? __typia_transform__randomInteger._randomInteger
)({
type: "integer",
}),
clerks: (_generator?.array ?? __typia_transform__randomArray._randomArray)({
type: "array",
element: () => _ro1(_recursive, _recursive ? 1 + _depth : _depth),
}),
});
const _ro1 = (_recursive = false, _depth = 0) => ({
name: (_generator?.string ?? __typia_transform__randomString._randomString)(
{
type: "string",
},
),
age: (_generator?.number ?? __typia_transform__randomNumber._randomNumber)({
type: "number",
exclusiveMinimum: 19,
maximum: 100,
}),
authority: (
_generator?.number ?? __typia_transform__randomNumber._randomNumber
)({
type: "number",
}),
joined_at: (
_generator?.date ?? __typia_transform__randomFormatDate._randomFormatDate
)(),
});
let _generator;
return (generator) => {
_generator = generator;
return _ro0();
};
})()();
const pruned = (() => {
const _pp0 = (input) =>
input.forEach((elem) => {
if ("object" === typeof elem && null !== elem) _po1(elem);
});
const _io0 = (input) =>
"string" === typeof input.id &&
/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(
input.id,
) &&
"string" === typeof input.name &&
3 <= input.name.length &&
"number" === typeof input.limit &&
Math.floor(input.limit) === input.limit &&
-2147483648 <= input.limit &&
input.limit <= 2147483647 &&
Array.isArray(input.clerks) &&
input.clerks.every(
(elem) => "object" === typeof elem && null !== elem && _io1(elem),
);
const _io1 = (input) =>
"string" === typeof input.name &&
"number" === typeof input.age &&
19 < input.age &&
input.age <= 100 &&
"number" === typeof input.authority &&
"string" === typeof input.joined_at &&
/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.test(input.joined_at);
const _ao0 = (input, _path, _exceptionable = true) =>
(("string" === typeof input.id &&
(/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(
input.id,
) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertPrune",
path: _path + ".id",
expected: 'string & Format<"uuid">',
value: input.id,
},
_errorFactory,
))) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertPrune",
path: _path + ".id",
expected: '(string & Format<"uuid">)',
value: input.id,
},
_errorFactory,
)) &&
(("string" === typeof input.name &&
(3 <= input.name.length ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertPrune",
path: _path + ".name",
expected: "string & MinLength<3>",
value: input.name,
},
_errorFactory,
))) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertPrune",
path: _path + ".name",
expected: "(string & MinLength<3>)",
value: input.name,
},
_errorFactory,
)) &&
(("number" === typeof input.limit &&
((Math.floor(input.limit) === input.limit &&
-2147483648 <= input.limit &&
input.limit <= 2147483647) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertPrune",
path: _path + ".limit",
expected: 'number & Type<"int32">',
value: input.limit,
},
_errorFactory,
))) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertPrune",
path: _path + ".limit",
expected: '(number & Type<"int32">)',
value: input.limit,
},
_errorFactory,
)) &&
(((Array.isArray(input.clerks) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertPrune",
path: _path + ".clerks",
expected: "Array<IClerk>",
value: input.clerks,
},
_errorFactory,
)) &&
input.clerks.every(
(elem, _index2) =>
((("object" === typeof elem && null !== elem) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertPrune",
path: _path + ".clerks[" + _index2 + "]",
expected: "IClerk",
value: elem,
},
_errorFactory,
)) &&
_ao1(
elem,
_path + ".clerks[" + _index2 + "]",
true && _exceptionable,
)) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertPrune",
path: _path + ".clerks[" + _index2 + "]",
expected: "IClerk",
value: elem,
},
_errorFactory,
),
)) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertPrune",
path: _path + ".clerks",
expected: "Array<IClerk>",
value: input.clerks,
},
_errorFactory,
));
const _ao1 = (input, _path, _exceptionable = true) =>
("string" === typeof input.name ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertPrune",
path: _path + ".name",
expected: "string",
value: input.name,
},
_errorFactory,
)) &&
(("number" === typeof input.age &&
(19 < input.age ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertPrune",
path: _path + ".age",
expected: "number & ExclusiveMinimum<19>",
value: input.age,
},
_errorFactory,
)) &&
(input.age <= 100 ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertPrune",
path: _path + ".age",
expected: "number & Maximum<100>",
value: input.age,
},
_errorFactory,
))) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertPrune",
path: _path + ".age",
expected: "(number & ExclusiveMinimum<19> & Maximum<100>)",
value: input.age,
},
_errorFactory,
)) &&
("number" === typeof input.authority ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertPrune",
path: _path + ".authority",
expected: "number",
value: input.authority,
},
_errorFactory,
)) &&
(("string" === typeof input.joined_at &&
(/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/.test(
input.joined_at,
) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertPrune",
path: _path + ".joined_at",
expected: 'string & Format<"date">',
value: input.joined_at,
},
_errorFactory,
))) ||
__typia_transform__assertGuard._assertGuard(
_exceptionable,
{
method: "typia.misc.assertPrune",
path: _path + ".joined_at",
expected: '(string & Format<"date">)',
value: input.joined_at,
},
_errorFactory,
));
const _po0 = (input) => {
if (Array.isArray(input.clerks)) _pp0(input.clerks);
for (const key of Object.keys(input)) {
if ("id" === key || "name" === key || "limit" === key || "clerks" === key)
continue;
delete input[key];
}
};
const _po1 = (input) => {
for (const key of Object.keys(input)) {
if (
"name" === key ||
"age" === key ||
"authority" === key ||
"joined_at" === key
)
continue;
delete input[key];
}
};
const __is = (input) =>
"object" === typeof input && null !== input && _io0(input);
let _errorFactory;
const __assert = (input, errorFactory) => {
if (false === __is(input)) {
_errorFactory = errorFactory;
((input, _path, _exceptionable = true) =>
((("object" === typeof input && null !== input) ||
__typia_transform__assertGuard._assertGuard(
true,
{
method: "typia.misc.assertPrune",
path: _path + "",
expected: "IDepartment",
value: input,
},
_errorFactory,
)) &&
_ao0(input, _path + "", true)) ||
__typia_transform__assertGuard._assertGuard(
true,
{
method: "typia.misc.assertPrune",
path: _path + "",
expected: "IDepartment",
value: input,
},
_errorFactory,
))(input, "$input", true);
}
return input;
};
const __prune = (input) => {
if ("object" === typeof input && null !== input) _po0(input);
};
return (input, errorFactory) => {
input = __assert(input, errorFactory);
__prune(input);
return input;
};
})()(department);
console.log(pruned);literals() function
export namespace misc {
export function literals<
T extends boolean | number | string | bigint | null,
>(): T[];
}Union literal type to array.
When you call typia.misc.literals<T>() function with union literal type, it returns an array of literal values listed in the generic T argument. This typia.misc.literals<T> function is useful when you are developing test program, especially handling some discriminated union types.
TypeScript Source Code
import typia from "typia";
typia.misc.literals<"A" | "B" | "C" | 1 | 2n>();Compiled JavaScript File
import typia from "typia";
[1, "A", "B", "C", BigInt(2)];notations module
camel() functions
undefined
export namespace notations {
export function camel<T>(input: T): CamelCase<T>;
export function assertCamel<T>(input: T | unknown): CamelCase<T>;
export function isCamel<T>(input: T | unknown): CamelCase<T> | null;
export function validateCamel<T>(
input: T | unknown,
): IValidation<CamelCase<T>>;
export function createCamel<T>(): (input: T) => CamelCase<T>;
export function createAssertCamel<T>(): (input: T | unknown) => CamelCase<T>;
export function createIsCamel<T>(): (
input: T | unknown,
) => CamelCase<T> | null;
export function createValidateCamel<T>(): (
input: T | unknown,
) => IValidation<CamelCase<T>>;
}undefined
/**
* Error thrown when type assertion fails.
*
* Thrown by {@link assert}, {@link assertGuard}, and other assert-family
* functions when input doesn't match expected type `T`. Contains detailed
* information about the first assertion failure:
*
* - `method`: Which typia function threw (e.g., `"typia.assert"`)
* - `path`: Property path where error occurred (e.g., `"input.user.age"`)
* - `expected`: Expected type string (e.g., `"number & ExclusiveMinimum<19>"`)
* - `value`: Actual value that failed validation
*
* @template T Expected type (for type safety)
*/
export class TypeGuardError<T = any> extends Error {
/**
* Name of the typia method that threw this error.
*
* E.g., `"typia.assert"`, `"typia.assertEquals"`, `"typia.assertGuard"`.
*/
public readonly method: string;
/**
* Property path where assertion failed.
*
* Uses dot notation for nested properties. `undefined` if error occurred at
* root level.
*
* E.g., `"input.age"`, `"input.profile.email"`, `"input[0].name"`.
*/
public readonly path: string | undefined;
/**
* String representation of expected type.
*
* E.g., `"string"`, `"number & ExclusiveMinimum<19>"`, `"{ name: string; age:
* number }"`.
*/
public readonly expected: string;
/**
* Actual value that failed assertion.
*
* The raw value at the error path, useful for debugging.
*/
public readonly value: unknown;
/**
* Optional human-readable error description.
*
* Primarily for AI agent libraries or custom validation scenarios needing
* additional context. Standard assertions rely on `path`, `expected`, and
* `value` for error reporting.
*/
public readonly description?: string | undefined;
/**
* Phantom property for TypeScript type safety.
*
* Not used at runtime—exists only to preserve generic type `T` in the type
* system. Always `undefined`.
*
* @internal
*/
protected readonly fake_expected_typed_value_?: T | undefined;
/**
* Creates a new TypeGuardError instance.
*
* @param props Error properties
*/
public constructor(props: TypeGuardError.IProps) {
// MESSAGE CONSTRUCTION
// Use custom message if provided, otherwise generate default format
super(
props.message ||
`Error on ${props.method}(): invalid type${
props.path ? ` on ${props.path}` : ""
}, expect to be ${props.expected}`,
);
// INHERITANCE POLYFILL
// Set up prototype for compatibility across different JavaScript environments
const proto = new.target.prototype;
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
else (this as any).__proto__ = proto;
// ASSIGN MEMBERS
this.method = props.method;
this.path = props.path;
this.expected = props.expected;
this.value = props.value;
if (props.description || props.value === undefined)
this.description =
props.description ??
[
"The value at this path is `undefined`.",
"",
`Please fill the \`${props.expected}\` typed value next time.`,
].join("\n");
}
}
export namespace TypeGuardError {
/** Properties for constructing a TypeGuardError. */
export interface IProps {
/**
* Name of the typia method that threw the error.
*
* E.g., `"typia.assert"`, `"typia.assertEquals"`.
*/
method: string;
/**
* Property path where assertion failed (optional).
*
* E.g., `"input.age"`, `"input.profile.email"`.
*/
path?: undefined | string;
/**
* String representation of expected type.
*
* E.g., `"string"`, `"number & ExclusiveMinimum<19>"`.
*/
expected: string;
/** Actual value that failed assertion. */
value: unknown;
/**
* Optional human-readable error description.
*
* For AI agent libraries or custom validation needing additional context.
*/
description?: string;
/**
* Custom error message (optional).
*
* If not provided, a default message is generated from other properties.
*/
message?: undefined | string;
}
}undefined
/**
* Validation result type with detailed error information.
*
* `IValidation<T>` is the return type of `typia.validate<T>()` and related
* validation functions. Unlike `typia.is<T>()` which returns a boolean, or
* `typia.assert<T>()` which throws exceptions, `typia.validate<T>()` returns
* this structured result with full error details.
*
* Check the {@link IValidation.success | success} discriminator:
*
* - `true` → {@link IValidation.ISuccess} with validated
* {@link IValidation.ISuccess.data | data}
* - `false` → {@link IValidation.IFailure} with
* {@link IValidation.IFailure.errors | errors} array
*
* This is the recommended validation function when you need to report
* validation errors to users or log them for debugging.
*
* @author Jeongho Nam - https://github.com/samchon
* @example
* const result = typia.validate<User>(input);
* if (result.success) {
* return result.data; // User type
* } else {
* result.errors.forEach((e) => console.log(e.path, e.expected));
* }
*
* @template T The expected type after successful validation
*/
export type IValidation<T = unknown> =
| IValidation.ISuccess<T>
| IValidation.IFailure;
export namespace IValidation {
/**
* Successful validation result.
*
* Indicates the input matches the expected type. The validated data is
* available in {@link data} with full type information.
*
* @template T The validated type
*/
export interface ISuccess<T = unknown> {
/**
* Success discriminator.
*
* Always `true` for successful validations. Use this to narrow the type
* before accessing {@link data}.
*/
success: true;
/**
* The validated data with correct type.
*
* The original input after successful validation. TypeScript will narrow
* this to type `T` when {@link success} is `true`.
*/
data: T;
}
/**
* Failed validation result with error details.
*
* Indicates the input did not match the expected type. Contains the original
* data and an array of all validation errors found.
*/
export interface IFailure {
/**
* Success discriminator.
*
* Always `false` for failed validations. Use this to narrow the type before
* accessing {@link errors}.
*/
success: false;
/**
* The original input that failed validation.
*
* Preserved as `unknown` type since it didn't match the expected type.
* Useful for debugging or logging the actual value.
*/
data: unknown;
/**
* Array of validation errors.
*
* Contains one entry for each validation failure found. Multiple errors may
* exist if the input has multiple type mismatches.
*/
errors: IError[];
}
/**
* Detailed information about a single validation error.
*
* Describes exactly what went wrong during validation, including the
* location, expected type, and actual value.
*/
export interface IError {
/**
* Property path to the error location.
*
* A dot-notation path from the root input to the failing property. Uses
* `$input` as the root. Example: `"$input.user.email"` or
* `"$input.items[0].price"`.
*/
path: string;
/**
* Expected type expression.
*
* A human-readable description of what type was expected at this location.
* Examples: `"string"`, `"number & ExclusiveMinimum<0>"`, `"(\"active\" |
* \"inactive\")"`.
*/
expected: string;
/**
* The actual value that failed validation.
*
* The value found at the error path. May be `undefined` if the property was
* missing. Useful for debugging type mismatches.
*/
value: unknown;
/**
* Human-readable error description.
*
* Optional additional context about the validation failure, such as
* constraint violations or custom error messages.
*/
description?: string;
}
}undefined
import { Equal } from "./internal/Equal";
import { IsTuple } from "./internal/IsTuple";
import { NativeClass } from "./internal/NativeClass";
import { ValueOf } from "./internal/ValueOf";
/**
* Converts all object keys to camelCase.
*
* `CamelCase<T>` transforms object property names to camelCase format and
* erases methods like {@link Resolved}. Recursively processes nested
* structures.
*
* @author Jeongho Nam - https://github.com/samchon
* @template T Target type to transform
*/
export type CamelCase<T> =
Equal<T, CamelizeMain<T>> extends true ? T : CamelizeMain<T>;
type CamelizeMain<T> = T extends [never]
? never // special trick for (jsonable | null) type
: T extends { valueOf(): boolean | bigint | number | string }
? ValueOf<T>
: T extends Function
? never
: T extends object
? CamelizeObject<T>
: T;
type CamelizeObject<T extends object> =
T extends Array<infer U>
? IsTuple<T> extends true
? CamelizeTuple<T>
: CamelizeMain<U>[]
: T extends Set<infer U>
? Set<CamelizeMain<U>>
: T extends Map<infer K, infer V>
? Map<CamelizeMain<K>, CamelizeMain<V>>
: T extends WeakSet<any> | WeakMap<any, any>
? never
: T extends NativeClass
? T
: {
[Key in keyof T as CamelizeString<Key & string>]: CamelizeMain<
T[Key]
>;
};
type CamelizeTuple<T extends readonly any[]> = T extends []
? []
: T extends [infer F]
? [CamelizeMain<F>]
: T extends [infer F, ...infer Rest extends readonly any[]]
? [CamelizeMain<F>, ...CamelizeTuple<Rest>]
: T extends [(infer F)?]
? [CamelizeMain<F>?]
: T extends [(infer F)?, ...infer Rest extends readonly any[]]
? [CamelizeMain<F>?, ...CamelizeTuple<Rest>]
: [];
type CamelizeString<Key extends string> = Key extends `_${infer R}`
? `_${CamelizeString<R>}`
: Key extends `${infer _F}_${infer _R}`
? CamelizeSnakeString<Key>
: Key extends Uppercase<Key>
? Lowercase<Key>
: CamelizePascalString<Key>;
type CamelizePascalString<Key extends string> =
Key extends `${infer F}${infer R}` ? `${Lowercase<F>}${R}` : Key;
type CamelizeSnakeString<Key extends string> = Key extends `_${infer R}`
? CamelizeSnakeString<R>
: Key extends `${infer F}_${infer M}${infer R}`
? M extends "_"
? CamelizeSnakeString<`${F}_${R}`>
: `${Lowercase<F>}${Uppercase<M>}${CamelizeSnakeString<R>}`
: Lowercase<Key>;Camel case converters.
Convert every property names of nested objects to be camel case notation.
When you need type safe functions, you can utilize below them.
typia.notations.assertCamel<T>():typia.assert<T>()+typia.notations.camel<T>()typia.notations.isCamel<T>:typia.is<T>()+typia.notations.camel<T>()typia.notations.validateCamel<T>:typia.validate<T>()+typia.notations.camel<T>()
TypeScript Source Code
import typia from "typia";
interface IPerson {
is_my_name_samchon?: boolean;
HelloTheNewWorld: string;
ToHTML: string;
}
typia.notations.createCamel<IPerson>();Compiled JavaScript File
import typia from "typia";
(() => {
const _co0 = (input) => ({
isMyNameSamchon: input.is_my_name_samchon,
helloTheNewWorld: input.HelloTheNewWorld,
toHTML: input.ToHTML,
});
return (input) => _co0(input);
})();pascal() functions
undefined
export namespace notations {
export function pascal<T>(input: T): PascalCase<T>;
export function assertPascal<T>(input: T | unknown): PascalCase<T>;
export function isPascal<T>(input: T | unknown): PascalCase<T> | null;
export function validatePascal<T>(
input: T | unknown,
): IValidation<PascalCase<T>>;
export function createPascal<T>(): (input: T) => PascalCase<T>;
export function createAssertPascal<T>(): (
input: T | unknown,
) => PascalCase<T>;
export function createIsPascal<T>(): (
input: T | unknown,
) => PascalCase<T> | null;
export function createValidatePascal<T>(): (
input: T | unknown,
) => IValidation<PascalCase<T>>;
}undefined
/**
* Error thrown when type assertion fails.
*
* Thrown by {@link assert}, {@link assertGuard}, and other assert-family
* functions when input doesn't match expected type `T`. Contains detailed
* information about the first assertion failure:
*
* - `method`: Which typia function threw (e.g., `"typia.assert"`)
* - `path`: Property path where error occurred (e.g., `"input.user.age"`)
* - `expected`: Expected type string (e.g., `"number & ExclusiveMinimum<19>"`)
* - `value`: Actual value that failed validation
*
* @template T Expected type (for type safety)
*/
export class TypeGuardError<T = any> extends Error {
/**
* Name of the typia method that threw this error.
*
* E.g., `"typia.assert"`, `"typia.assertEquals"`, `"typia.assertGuard"`.
*/
public readonly method: string;
/**
* Property path where assertion failed.
*
* Uses dot notation for nested properties. `undefined` if error occurred at
* root level.
*
* E.g., `"input.age"`, `"input.profile.email"`, `"input[0].name"`.
*/
public readonly path: string | undefined;
/**
* String representation of expected type.
*
* E.g., `"string"`, `"number & ExclusiveMinimum<19>"`, `"{ name: string; age:
* number }"`.
*/
public readonly expected: string;
/**
* Actual value that failed assertion.
*
* The raw value at the error path, useful for debugging.
*/
public readonly value: unknown;
/**
* Optional human-readable error description.
*
* Primarily for AI agent libraries or custom validation scenarios needing
* additional context. Standard assertions rely on `path`, `expected`, and
* `value` for error reporting.
*/
public readonly description?: string | undefined;
/**
* Phantom property for TypeScript type safety.
*
* Not used at runtime—exists only to preserve generic type `T` in the type
* system. Always `undefined`.
*
* @internal
*/
protected readonly fake_expected_typed_value_?: T | undefined;
/**
* Creates a new TypeGuardError instance.
*
* @param props Error properties
*/
public constructor(props: TypeGuardError.IProps) {
// MESSAGE CONSTRUCTION
// Use custom message if provided, otherwise generate default format
super(
props.message ||
`Error on ${props.method}(): invalid type${
props.path ? ` on ${props.path}` : ""
}, expect to be ${props.expected}`,
);
// INHERITANCE POLYFILL
// Set up prototype for compatibility across different JavaScript environments
const proto = new.target.prototype;
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
else (this as any).__proto__ = proto;
// ASSIGN MEMBERS
this.method = props.method;
this.path = props.path;
this.expected = props.expected;
this.value = props.value;
if (props.description || props.value === undefined)
this.description =
props.description ??
[
"The value at this path is `undefined`.",
"",
`Please fill the \`${props.expected}\` typed value next time.`,
].join("\n");
}
}
export namespace TypeGuardError {
/** Properties for constructing a TypeGuardError. */
export interface IProps {
/**
* Name of the typia method that threw the error.
*
* E.g., `"typia.assert"`, `"typia.assertEquals"`.
*/
method: string;
/**
* Property path where assertion failed (optional).
*
* E.g., `"input.age"`, `"input.profile.email"`.
*/
path?: undefined | string;
/**
* String representation of expected type.
*
* E.g., `"string"`, `"number & ExclusiveMinimum<19>"`.
*/
expected: string;
/** Actual value that failed assertion. */
value: unknown;
/**
* Optional human-readable error description.
*
* For AI agent libraries or custom validation needing additional context.
*/
description?: string;
/**
* Custom error message (optional).
*
* If not provided, a default message is generated from other properties.
*/
message?: undefined | string;
}
}undefined
/**
* Validation result type with detailed error information.
*
* `IValidation<T>` is the return type of `typia.validate<T>()` and related
* validation functions. Unlike `typia.is<T>()` which returns a boolean, or
* `typia.assert<T>()` which throws exceptions, `typia.validate<T>()` returns
* this structured result with full error details.
*
* Check the {@link IValidation.success | success} discriminator:
*
* - `true` → {@link IValidation.ISuccess} with validated
* {@link IValidation.ISuccess.data | data}
* - `false` → {@link IValidation.IFailure} with
* {@link IValidation.IFailure.errors | errors} array
*
* This is the recommended validation function when you need to report
* validation errors to users or log them for debugging.
*
* @author Jeongho Nam - https://github.com/samchon
* @example
* const result = typia.validate<User>(input);
* if (result.success) {
* return result.data; // User type
* } else {
* result.errors.forEach((e) => console.log(e.path, e.expected));
* }
*
* @template T The expected type after successful validation
*/
export type IValidation<T = unknown> =
| IValidation.ISuccess<T>
| IValidation.IFailure;
export namespace IValidation {
/**
* Successful validation result.
*
* Indicates the input matches the expected type. The validated data is
* available in {@link data} with full type information.
*
* @template T The validated type
*/
export interface ISuccess<T = unknown> {
/**
* Success discriminator.
*
* Always `true` for successful validations. Use this to narrow the type
* before accessing {@link data}.
*/
success: true;
/**
* The validated data with correct type.
*
* The original input after successful validation. TypeScript will narrow
* this to type `T` when {@link success} is `true`.
*/
data: T;
}
/**
* Failed validation result with error details.
*
* Indicates the input did not match the expected type. Contains the original
* data and an array of all validation errors found.
*/
export interface IFailure {
/**
* Success discriminator.
*
* Always `false` for failed validations. Use this to narrow the type before
* accessing {@link errors}.
*/
success: false;
/**
* The original input that failed validation.
*
* Preserved as `unknown` type since it didn't match the expected type.
* Useful for debugging or logging the actual value.
*/
data: unknown;
/**
* Array of validation errors.
*
* Contains one entry for each validation failure found. Multiple errors may
* exist if the input has multiple type mismatches.
*/
errors: IError[];
}
/**
* Detailed information about a single validation error.
*
* Describes exactly what went wrong during validation, including the
* location, expected type, and actual value.
*/
export interface IError {
/**
* Property path to the error location.
*
* A dot-notation path from the root input to the failing property. Uses
* `$input` as the root. Example: `"$input.user.email"` or
* `"$input.items[0].price"`.
*/
path: string;
/**
* Expected type expression.
*
* A human-readable description of what type was expected at this location.
* Examples: `"string"`, `"number & ExclusiveMinimum<0>"`, `"(\"active\" |
* \"inactive\")"`.
*/
expected: string;
/**
* The actual value that failed validation.
*
* The value found at the error path. May be `undefined` if the property was
* missing. Useful for debugging type mismatches.
*/
value: unknown;
/**
* Human-readable error description.
*
* Optional additional context about the validation failure, such as
* constraint violations or custom error messages.
*/
description?: string;
}
}undefined
import { Equal } from "./internal/Equal";
import { IsTuple } from "./internal/IsTuple";
import { NativeClass } from "./internal/NativeClass";
import { ValueOf } from "./internal/ValueOf";
/**
* Converts all object keys to PascalCase.
*
* `PascalCase<T>` transforms object property names to PascalCase format and
* erases methods like {@link Resolved}. Recursively processes nested
* structures.
*
* @author Jeongho Nam - https://github.com/samchon
* @template T Target type to transform
*/
export type PascalCase<T> =
Equal<T, PascalizeMain<T>> extends true ? T : PascalizeMain<T>;
type PascalizeMain<T> = T extends [never]
? never // special trick for (jsonable | null) type
: T extends { valueOf(): boolean | bigint | number | string }
? ValueOf<T>
: T extends Function
? never
: T extends object
? PascalizeObject<T>
: T;
type PascalizeObject<T extends object> =
T extends Array<infer U>
? IsTuple<T> extends true
? PascalizeTuple<T>
: PascalizeMain<U>[]
: T extends Set<infer U>
? Set<PascalizeMain<U>>
: T extends Map<infer K, infer V>
? Map<PascalizeMain<K>, PascalizeMain<V>>
: T extends WeakSet<any> | WeakMap<any, any>
? never
: T extends NativeClass
? T
: {
[Key in keyof T as PascalizeString<
Key & string
>]: PascalizeMain<T[Key]>;
};
type PascalizeTuple<T extends readonly any[]> = T extends []
? []
: T extends [infer F]
? [PascalizeMain<F>]
: T extends [infer F, ...infer Rest extends readonly any[]]
? [PascalizeMain<F>, ...PascalizeTuple<Rest>]
: T extends [(infer F)?]
? [PascalizeMain<F>?]
: T extends [(infer F)?, ...infer Rest extends readonly any[]]
? [PascalizeMain<F>?, ...PascalizeTuple<Rest>]
: [];
type PascalizeString<Key extends string> = Key extends `_${infer R}`
? `_${PascalizeString<R>}`
: Key extends `${infer _F}_${infer _R}`
? PascalizeSnakeString<Key>
: Capitalize<Key>;
type PascalizeSnakeString<Key extends string> = Key extends `_${infer R}`
? PascalizeSnakeString<R>
: Key extends `${infer F}${infer M}_${infer R}`
? `${Uppercase<F>}${Lowercase<M>}${PascalizeSnakeString<R>}`
: Key extends `${infer F}${infer R}`
? `${Uppercase<F>}${Lowercase<R>}`
: Key;Pascal case converters.
Convert every property names of nested objects to be pascal case notation.
When you need type safe functions, you can utilize below them.
typia.notations.assertPascal<T>():typia.assert<T>()+typia.notations.pascal<T>()typia.notations.isPascal<T>:typia.is<T>()+typia.notations.pascal<T>()typia.notations.validatePascal<T>:typia.validate<T>()+typia.notations.pascal<T>()
TypeScript Source Code
import typia from "typia";
interface IPerson {
is_my_name_samchon?: boolean;
helloTheNewWorld: string;
toHTML: string;
}
typia.notations.createPascal<IPerson>();Compiled JavaScript File
import typia from "typia";
(() => {
const _co0 = (input) => ({
IsMyNameSamchon: input.is_my_name_samchon,
HelloTheNewWorld: input.helloTheNewWorld,
ToHTML: input.toHTML,
});
return (input) => _co0(input);
})();snake() functions
undefined
export namespace notations {
export function snake<T>(input: T): SnakeCase<T>;
export function assertSnake<T>(input: T | unknown): SnakeCase<T>;
export function isSnake<T>(input: T | unknown): SnakeCase<T> | null;
export function validateSnake<T>(
input: T | unknown,
): IValidation<SnakeCase<T>>;
export function createSnake<T>(): (input: T) => SnakeCase<T>;
export function createAssertSnake<T>(): (input: T | unknown) => SnakeCase<T>;
export function createIsSnake<T>(): (
input: T | unknown,
) => SnakeCase<T> | null;
export function createValidateSnake<T>(): (
input: T | unknown,
) => IValidation<SnakeCase<T>>;
}undefined
/**
* Error thrown when type assertion fails.
*
* Thrown by {@link assert}, {@link assertGuard}, and other assert-family
* functions when input doesn't match expected type `T`. Contains detailed
* information about the first assertion failure:
*
* - `method`: Which typia function threw (e.g., `"typia.assert"`)
* - `path`: Property path where error occurred (e.g., `"input.user.age"`)
* - `expected`: Expected type string (e.g., `"number & ExclusiveMinimum<19>"`)
* - `value`: Actual value that failed validation
*
* @template T Expected type (for type safety)
*/
export class TypeGuardError<T = any> extends Error {
/**
* Name of the typia method that threw this error.
*
* E.g., `"typia.assert"`, `"typia.assertEquals"`, `"typia.assertGuard"`.
*/
public readonly method: string;
/**
* Property path where assertion failed.
*
* Uses dot notation for nested properties. `undefined` if error occurred at
* root level.
*
* E.g., `"input.age"`, `"input.profile.email"`, `"input[0].name"`.
*/
public readonly path: string | undefined;
/**
* String representation of expected type.
*
* E.g., `"string"`, `"number & ExclusiveMinimum<19>"`, `"{ name: string; age:
* number }"`.
*/
public readonly expected: string;
/**
* Actual value that failed assertion.
*
* The raw value at the error path, useful for debugging.
*/
public readonly value: unknown;
/**
* Optional human-readable error description.
*
* Primarily for AI agent libraries or custom validation scenarios needing
* additional context. Standard assertions rely on `path`, `expected`, and
* `value` for error reporting.
*/
public readonly description?: string | undefined;
/**
* Phantom property for TypeScript type safety.
*
* Not used at runtime—exists only to preserve generic type `T` in the type
* system. Always `undefined`.
*
* @internal
*/
protected readonly fake_expected_typed_value_?: T | undefined;
/**
* Creates a new TypeGuardError instance.
*
* @param props Error properties
*/
public constructor(props: TypeGuardError.IProps) {
// MESSAGE CONSTRUCTION
// Use custom message if provided, otherwise generate default format
super(
props.message ||
`Error on ${props.method}(): invalid type${
props.path ? ` on ${props.path}` : ""
}, expect to be ${props.expected}`,
);
// INHERITANCE POLYFILL
// Set up prototype for compatibility across different JavaScript environments
const proto = new.target.prototype;
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
else (this as any).__proto__ = proto;
// ASSIGN MEMBERS
this.method = props.method;
this.path = props.path;
this.expected = props.expected;
this.value = props.value;
if (props.description || props.value === undefined)
this.description =
props.description ??
[
"The value at this path is `undefined`.",
"",
`Please fill the \`${props.expected}\` typed value next time.`,
].join("\n");
}
}
export namespace TypeGuardError {
/** Properties for constructing a TypeGuardError. */
export interface IProps {
/**
* Name of the typia method that threw the error.
*
* E.g., `"typia.assert"`, `"typia.assertEquals"`.
*/
method: string;
/**
* Property path where assertion failed (optional).
*
* E.g., `"input.age"`, `"input.profile.email"`.
*/
path?: undefined | string;
/**
* String representation of expected type.
*
* E.g., `"string"`, `"number & ExclusiveMinimum<19>"`.
*/
expected: string;
/** Actual value that failed assertion. */
value: unknown;
/**
* Optional human-readable error description.
*
* For AI agent libraries or custom validation needing additional context.
*/
description?: string;
/**
* Custom error message (optional).
*
* If not provided, a default message is generated from other properties.
*/
message?: undefined | string;
}
}undefined
/**
* Validation result type with detailed error information.
*
* `IValidation<T>` is the return type of `typia.validate<T>()` and related
* validation functions. Unlike `typia.is<T>()` which returns a boolean, or
* `typia.assert<T>()` which throws exceptions, `typia.validate<T>()` returns
* this structured result with full error details.
*
* Check the {@link IValidation.success | success} discriminator:
*
* - `true` → {@link IValidation.ISuccess} with validated
* {@link IValidation.ISuccess.data | data}
* - `false` → {@link IValidation.IFailure} with
* {@link IValidation.IFailure.errors | errors} array
*
* This is the recommended validation function when you need to report
* validation errors to users or log them for debugging.
*
* @author Jeongho Nam - https://github.com/samchon
* @example
* const result = typia.validate<User>(input);
* if (result.success) {
* return result.data; // User type
* } else {
* result.errors.forEach((e) => console.log(e.path, e.expected));
* }
*
* @template T The expected type after successful validation
*/
export type IValidation<T = unknown> =
| IValidation.ISuccess<T>
| IValidation.IFailure;
export namespace IValidation {
/**
* Successful validation result.
*
* Indicates the input matches the expected type. The validated data is
* available in {@link data} with full type information.
*
* @template T The validated type
*/
export interface ISuccess<T = unknown> {
/**
* Success discriminator.
*
* Always `true` for successful validations. Use this to narrow the type
* before accessing {@link data}.
*/
success: true;
/**
* The validated data with correct type.
*
* The original input after successful validation. TypeScript will narrow
* this to type `T` when {@link success} is `true`.
*/
data: T;
}
/**
* Failed validation result with error details.
*
* Indicates the input did not match the expected type. Contains the original
* data and an array of all validation errors found.
*/
export interface IFailure {
/**
* Success discriminator.
*
* Always `false` for failed validations. Use this to narrow the type before
* accessing {@link errors}.
*/
success: false;
/**
* The original input that failed validation.
*
* Preserved as `unknown` type since it didn't match the expected type.
* Useful for debugging or logging the actual value.
*/
data: unknown;
/**
* Array of validation errors.
*
* Contains one entry for each validation failure found. Multiple errors may
* exist if the input has multiple type mismatches.
*/
errors: IError[];
}
/**
* Detailed information about a single validation error.
*
* Describes exactly what went wrong during validation, including the
* location, expected type, and actual value.
*/
export interface IError {
/**
* Property path to the error location.
*
* A dot-notation path from the root input to the failing property. Uses
* `$input` as the root. Example: `"$input.user.email"` or
* `"$input.items[0].price"`.
*/
path: string;
/**
* Expected type expression.
*
* A human-readable description of what type was expected at this location.
* Examples: `"string"`, `"number & ExclusiveMinimum<0>"`, `"(\"active\" |
* \"inactive\")"`.
*/
expected: string;
/**
* The actual value that failed validation.
*
* The value found at the error path. May be `undefined` if the property was
* missing. Useful for debugging type mismatches.
*/
value: unknown;
/**
* Human-readable error description.
*
* Optional additional context about the validation failure, such as
* constraint violations or custom error messages.
*/
description?: string;
}
}undefined
import { Equal } from "./internal/Equal";
import { NativeClass } from "./internal/NativeClass";
import { ValueOf } from "./internal/ValueOf";
/**
* Converts all object keys to snake_case.
*
* `SnakeCase<T>` transforms object property names to snake_case format and
* erases methods like {@link Resolved}. Recursively processes nested
* structures.
*
* @author Jeongho Nam - https://github.com/samchon
* @template T Target type to transform
*/
export type SnakeCase<T> =
Equal<T, SnakageMain<T>> extends true ? T : SnakageMain<T>;
/* -----------------------------------------------------------
OBJECT CONVERSION
----------------------------------------------------------- */
type SnakageMain<T> = T extends [never]
? never // special trick for (jsonable | null) type
: T extends { valueOf(): boolean | bigint | number | string }
? ValueOf<T>
: T extends Function
? never
: T extends object
? SnakageObject<T>
: T;
type SnakageObject<T extends object> =
T extends Array<infer U>
? IsTuple<T> extends true
? SnakageTuple<T>
: SnakageMain<U>[]
: T extends Set<infer U>
? Set<SnakageMain<U>>
: T extends Map<infer K, infer V>
? Map<SnakageMain<K>, SnakageMain<V>>
: T extends WeakSet<any> | WeakMap<any, any>
? never
: T extends NativeClass
? T
: {
[Key in keyof T as SnakageString<Key & string>]: SnakageMain<
T[Key]
>;
};
/* -----------------------------------------------------------
SPECIAL CASES
----------------------------------------------------------- */
type IsTuple<T extends readonly any[] | { length: number }> = [T] extends [
never,
]
? false
: T extends readonly any[]
? number extends T["length"]
? false
: true
: false;
type SnakageTuple<T extends readonly any[]> = T extends []
? []
: T extends [infer F]
? [SnakageMain<F>]
: T extends [infer F, ...infer Rest extends readonly any[]]
? [SnakageMain<F>, ...SnakageTuple<Rest>]
: T extends [(infer F)?]
? [SnakageMain<F>?]
: T extends [(infer F)?, ...infer Rest extends readonly any[]]
? [SnakageMain<F>?, ...SnakageTuple<Rest>]
: [];
/* -----------------------------------------------------------
STRING CONVERTER
----------------------------------------------------------- */
type SnakageString<Key extends string> = Key extends `${infer _}`
? SnakageStringRepeatedly<Key, "">
: Key;
type SnakageStringRepeatedly<
S extends string,
Previous extends string,
> = S extends `${infer First}${infer Second}${infer Rest}`
? `${Underscore<Previous, First>}${Lowercase<First>}${Underscore<
First,
Second
>}${Lowercase<Second>}${SnakageStringRepeatedly<Rest, Second>}`
: S extends `${infer First}`
? `${Underscore<Previous, First>}${Lowercase<First>}`
: "";
type Underscore<First extends string, Second extends string> = First extends
| UpperAlphabetic
| ""
| "_"
? ""
: Second extends UpperAlphabetic
? "_"
: "";
type UpperAlphabetic =
| "A"
| "B"
| "C"
| "D"
| "E"
| "F"
| "G"
| "H"
| "I"
| "J"
| "K"
| "L"
| "M"
| "N"
| "O"
| "P"
| "Q"
| "R"
| "S"
| "T"
| "U"
| "V"
| "W"
| "X"
| "Y"
| "Z";Snake case converters.
Convert every property names of nested objects to be snake case notation.
When you need type safe functions, you can utilize below them.
typia.notations.assertSnake<T>():typia.assert<T>()+typia.notations.snake<T>()typia.notations.isSnake<T>:typia.is<T>()+typia.notations.snake<T>()typia.notations.validateSnake<T>:typia.validate<T>()+typia.notations.snake<T>()
TypeScript Source Code
import typia from "typia";
interface IPerson {
isMyNameSamchon?: boolean;
HelloTheNewWorld: string;
ToHTML: string;
}
typia.notations.createSnake<IPerson>();Compiled JavaScript File
import typia from "typia";
(() => {
const _co0 = (input) => ({
is_my_name_samchon: input.isMyNameSamchon,
hello_the_new_world: input.HelloTheNewWorld,
to_html: input.ToHTML,
});
return (input) => _co0(input);
})();http module
Nestia Supporting
http module has been designed to support the nestia project.
query()functions ->@TypedQuery()headers()functions ->@TypedHeaders()parameter()function ->@TypedParam()
query() functions
undefined
export namespace http {
export function query<T extends object>(input: Query): Resolved<T>;
export function assertQuery<T extends object>(input: Query): Resolved<T>;
export function isQuery<T extends object>(input: Query): Resolved<T> | null;
export function validateQuery<T extends object>(
input: Query,
): IValidation<Resolved<T>>;
export function createQuery<T extends object>(): (
input: Query,
) => Resolved<T>;
export function createAssertQuery<T extends object>(): (
input: Query,
) => Resolved<T>;
export function createIsQuery<T extends object>(): (
input: Query,
) => Resolved<T> | null;
export function createValidateQuery<T extends object>(): (
input: Query,
) => IValidation<Resolved<T>>;
}
type Query = string | URLSearchParams;undefined
/**
* Error thrown when type assertion fails.
*
* Thrown by {@link assert}, {@link assertGuard}, and other assert-family
* functions when input doesn't match expected type `T`. Contains detailed
* information about the first assertion failure:
*
* - `method`: Which typia function threw (e.g., `"typia.assert"`)
* - `path`: Property path where error occurred (e.g., `"input.user.age"`)
* - `expected`: Expected type string (e.g., `"number & ExclusiveMinimum<19>"`)
* - `value`: Actual value that failed validation
*
* @template T Expected type (for type safety)
*/
export class TypeGuardError<T = any> extends Error {
/**
* Name of the typia method that threw this error.
*
* E.g., `"typia.assert"`, `"typia.assertEquals"`, `"typia.assertGuard"`.
*/
public readonly method: string;
/**
* Property path where assertion failed.
*
* Uses dot notation for nested properties. `undefined` if error occurred at
* root level.
*
* E.g., `"input.age"`, `"input.profile.email"`, `"input[0].name"`.
*/
public readonly path: string | undefined;
/**
* String representation of expected type.
*
* E.g., `"string"`, `"number & ExclusiveMinimum<19>"`, `"{ name: string; age:
* number }"`.
*/
public readonly expected: string;
/**
* Actual value that failed assertion.
*
* The raw value at the error path, useful for debugging.
*/
public readonly value: unknown;
/**
* Optional human-readable error description.
*
* Primarily for AI agent libraries or custom validation scenarios needing
* additional context. Standard assertions rely on `path`, `expected`, and
* `value` for error reporting.
*/
public readonly description?: string | undefined;
/**
* Phantom property for TypeScript type safety.
*
* Not used at runtime—exists only to preserve generic type `T` in the type
* system. Always `undefined`.
*
* @internal
*/
protected readonly fake_expected_typed_value_?: T | undefined;
/**
* Creates a new TypeGuardError instance.
*
* @param props Error properties
*/
public constructor(props: TypeGuardError.IProps) {
// MESSAGE CONSTRUCTION
// Use custom message if provided, otherwise generate default format
super(
props.message ||
`Error on ${props.method}(): invalid type${
props.path ? ` on ${props.path}` : ""
}, expect to be ${props.expected}`,
);
// INHERITANCE POLYFILL
// Set up prototype for compatibility across different JavaScript environments
const proto = new.target.prototype;
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
else (this as any).__proto__ = proto;
// ASSIGN MEMBERS
this.method = props.method;
this.path = props.path;
this.expected = props.expected;
this.value = props.value;
if (props.description || props.value === undefined)
this.description =
props.description ??
[
"The value at this path is `undefined`.",
"",
`Please fill the \`${props.expected}\` typed value next time.`,
].join("\n");
}
}
export namespace TypeGuardError {
/** Properties for constructing a TypeGuardError. */
export interface IProps {
/**
* Name of the typia method that threw the error.
*
* E.g., `"typia.assert"`, `"typia.assertEquals"`.
*/
method: string;
/**
* Property path where assertion failed (optional).
*
* E.g., `"input.age"`, `"input.profile.email"`.
*/
path?: undefined | string;
/**
* String representation of expected type.
*
* E.g., `"string"`, `"number & ExclusiveMinimum<19>"`.
*/
expected: string;
/** Actual value that failed assertion. */
value: unknown;
/**
* Optional human-readable error description.
*
* For AI agent libraries or custom validation needing additional context.
*/
description?: string;
/**
* Custom error message (optional).
*
* If not provided, a default message is generated from other properties.
*/
message?: undefined | string;
}
}undefined
/**
* Validation result type with detailed error information.
*
* `IValidation<T>` is the return type of `typia.validate<T>()` and related
* validation functions. Unlike `typia.is<T>()` which returns a boolean, or
* `typia.assert<T>()` which throws exceptions, `typia.validate<T>()` returns
* this structured result with full error details.
*
* Check the {@link IValidation.success | success} discriminator:
*
* - `true` → {@link IValidation.ISuccess} with validated
* {@link IValidation.ISuccess.data | data}
* - `false` → {@link IValidation.IFailure} with
* {@link IValidation.IFailure.errors | errors} array
*
* This is the recommended validation function when you need to report
* validation errors to users or log them for debugging.
*
* @author Jeongho Nam - https://github.com/samchon
* @example
* const result = typia.validate<User>(input);
* if (result.success) {
* return result.data; // User type
* } else {
* result.errors.forEach((e) => console.log(e.path, e.expected));
* }
*
* @template T The expected type after successful validation
*/
export type IValidation<T = unknown> =
| IValidation.ISuccess<T>
| IValidation.IFailure;
export namespace IValidation {
/**
* Successful validation result.
*
* Indicates the input matches the expected type. The validated data is
* available in {@link data} with full type information.
*
* @template T The validated type
*/
export interface ISuccess<T = unknown> {
/**
* Success discriminator.
*
* Always `true` for successful validations. Use this to narrow the type
* before accessing {@link data}.
*/
success: true;
/**
* The validated data with correct type.
*
* The original input after successful validation. TypeScript will narrow
* this to type `T` when {@link success} is `true`.
*/
data: T;
}
/**
* Failed validation result with error details.
*
* Indicates the input did not match the expected type. Contains the original
* data and an array of all validation errors found.
*/
export interface IFailure {
/**
* Success discriminator.
*
* Always `false` for failed validations. Use this to narrow the type before
* accessing {@link errors}.
*/
success: false;
/**
* The original input that failed validation.
*
* Preserved as `unknown` type since it didn't match the expected type.
* Useful for debugging or logging the actual value.
*/
data: unknown;
/**
* Array of validation errors.
*
* Contains one entry for each validation failure found. Multiple errors may
* exist if the input has multiple type mismatches.
*/
errors: IError[];
}
/**
* Detailed information about a single validation error.
*
* Describes exactly what went wrong during validation, including the
* location, expected type, and actual value.
*/
export interface IError {
/**
* Property path to the error location.
*
* A dot-notation path from the root input to the failing property. Uses
* `$input` as the root. Example: `"$input.user.email"` or
* `"$input.items[0].price"`.
*/
path: string;
/**
* Expected type expression.
*
* A human-readable description of what type was expected at this location.
* Examples: `"string"`, `"number & ExclusiveMinimum<0>"`, `"(\"active\" |
* \"inactive\")"`.
*/
expected: string;
/**
* The actual value that failed validation.
*
* The value found at the error path. May be `undefined` if the property was
* missing. Useful for debugging type mismatches.
*/
value: unknown;
/**
* Human-readable error description.
*
* Optional additional context about the validation failure, such as
* constraint violations or custom error messages.
*/
description?: string;
}
}undefined
import { Equal } from "./internal/Equal";
import { IsTuple } from "./internal/IsTuple";
import { NativeClass } from "./internal/NativeClass";
import { ValueOf } from "./internal/ValueOf";
/**
* Converts a type to its resolved form by erasing all methods.
*
* `Resolved<T>` transforms classes to plain objects, extracts primitive values
* from boxed types (Boolean→boolean, Number→number, String→string), and
* recursively processes nested structures. Native classes (Date, Set, Map,
* etc.) are preserved unchanged.
*
* @author Jeongho Nam - https://github.com/samchon
* @author Kyungsu Kang - https://github.com/kakasoo
* @template T Target type to resolve
*/
export type Resolved<T> =
Equal<T, ResolvedMain<T>> extends true ? T : ResolvedMain<T>;
type ResolvedMain<T> = T extends [never]
? never // (special trick for jsonable | null) type
: ValueOf<T> extends boolean | number | bigint | string
? ValueOf<T>
: T extends Function
? never
: T extends object
? ResolvedObject<T>
: ValueOf<T>;
type ResolvedObject<T extends object> =
T extends Array<infer U>
? IsTuple<T> extends true
? ResolvedTuple<T>
: ResolvedMain<U>[]
: T extends Set<infer U>
? Set<ResolvedMain<U>>
: T extends Map<infer K, infer V>
? Map<ResolvedMain<K>, ResolvedMain<V>>
: T extends WeakSet<any> | WeakMap<any, any>
? never
: T extends NativeClass
? T
: {
[P in keyof T]: ResolvedMain<T[P]>;
};
type ResolvedTuple<T extends readonly any[]> = T extends []
? []
: T extends [infer F]
? [ResolvedMain<F>]
: T extends [infer F, ...infer Rest extends readonly any[]]
? [ResolvedMain<F>, ...ResolvedTuple<Rest>]
: T extends [(infer F)?]
? [ResolvedMain<F>?]
: T extends [(infer F)?, ...infer Rest extends readonly any[]]
? [ResolvedMain<F>?, ...ResolvedTuple<Rest>]
: [];URL query decoder functions.
typia.http.query<T>() is a function decoding a query string or an URLSearchParams instance, with automatic type casting to the expected type. When property type be defined as boolean or number type, typia.http.query<T>() will cast the value to the expected type when decoding.
By the way, as URL query is not enough to express complex data structures, typia.http.query<T>() function has some limitations. If target type T is not following those restrictions, compilation errors would be occurred.
- Type T must be an object type
- Do not allow dynamic property
- Only boolean, bigint, number, string or their array types are allowed
- By the way, union type never be not allowed
Also, typia.http.query<T>() function does not perform validation about the decoded value. Therefore, if you can’t sure that input data is following the T type, it would better to call one of below functions instead.
typia.http.assertQuery<T>():typia.assert<T>()+typia.http.query<T>()typia.http.isQuery<T>():typia.is<T>()+typia.http.query<T>()typia.http.validateQuery<T>():typia.validate<T>()+typia.http.query<T>()
TypeScript Source Code
import typia from "typia";
interface IQuery {
limit?: number;
enforce: boolean;
values?: string[];
atomic: string | null;
indexes: number[];
}
typia.http.createQuery<IQuery>();Compiled JavaScript File
import typia from "typia";
import * as __typia_transform__httpQueryParseURLSearchParams from "typia/lib/internal/_httpQueryParseURLSearchParams";
import * as __typia_transform__httpQueryReadArray from "typia/lib/internal/_httpQueryReadArray";
import * as __typia_transform__httpQueryReadBoolean from "typia/lib/internal/_httpQueryReadBoolean";
import * as __typia_transform__httpQueryReadNumber from "typia/lib/internal/_httpQueryReadNumber";
import * as __typia_transform__httpQueryReadString from "typia/lib/internal/_httpQueryReadString";
(() => {
return (input) => {
input =
__typia_transform__httpQueryParseURLSearchParams._httpQueryParseURLSearchParams(
input,
);
const output = {
limit:
__typia_transform__httpQueryReadNumber._httpQueryReadNumber(
input.get("limit"),
) ?? undefined,
enforce: __typia_transform__httpQueryReadBoolean._httpQueryReadBoolean(
input.get("enforce"),
),
values: __typia_transform__httpQueryReadArray._httpQueryReadArray(
input
.getAll("values")
.map((elem) =>
__typia_transform__httpQueryReadString._httpQueryReadString(elem),
),
undefined,
),
atomic: __typia_transform__httpQueryReadString._httpQueryReadString(
input.get("atomic"),
),
indexes: input
.getAll("indexes")
.map((elem) =>
__typia_transform__httpQueryReadNumber._httpQueryReadNumber(elem),
),
};
return output;
};
})();headers() functions
undefined
export namespace http {
export function headers<T extends object>(input: Headers): Resolved<T>;
export function assertHeaders<T extends object>(input: Headers): Resolved<T>;
export function isHeaders<T extends object>(
input: Headers,
): Resolved<T> | null;
export function validateHeaders<T extends object>(
input: Headers,
): IValidation<Resolved<T>>;
export function createHeaders<T extends object>(): (
input: Headers,
) => Resolved<T>;
export function createAssertHeaders<T extends object>(): (
input: Headers,
) => Resolved<T>;
export function createIsHeaders<T extends object>(): (
input: Headers,
) => Resolved<T> | null;
export function createValidateHeaders<T extends object>(): (
input: Headers,
) => IValidation<Resolved<T>>;
}
type Headers = Record<string, string | string[] | undefined>;undefined
/**
* Error thrown when type assertion fails.
*
* Thrown by {@link assert}, {@link assertGuard}, and other assert-family
* functions when input doesn't match expected type `T`. Contains detailed
* information about the first assertion failure:
*
* - `method`: Which typia function threw (e.g., `"typia.assert"`)
* - `path`: Property path where error occurred (e.g., `"input.user.age"`)
* - `expected`: Expected type string (e.g., `"number & ExclusiveMinimum<19>"`)
* - `value`: Actual value that failed validation
*
* @template T Expected type (for type safety)
*/
export class TypeGuardError<T = any> extends Error {
/**
* Name of the typia method that threw this error.
*
* E.g., `"typia.assert"`, `"typia.assertEquals"`, `"typia.assertGuard"`.
*/
public readonly method: string;
/**
* Property path where assertion failed.
*
* Uses dot notation for nested properties. `undefined` if error occurred at
* root level.
*
* E.g., `"input.age"`, `"input.profile.email"`, `"input[0].name"`.
*/
public readonly path: string | undefined;
/**
* String representation of expected type.
*
* E.g., `"string"`, `"number & ExclusiveMinimum<19>"`, `"{ name: string; age:
* number }"`.
*/
public readonly expected: string;
/**
* Actual value that failed assertion.
*
* The raw value at the error path, useful for debugging.
*/
public readonly value: unknown;
/**
* Optional human-readable error description.
*
* Primarily for AI agent libraries or custom validation scenarios needing
* additional context. Standard assertions rely on `path`, `expected`, and
* `value` for error reporting.
*/
public readonly description?: string | undefined;
/**
* Phantom property for TypeScript type safety.
*
* Not used at runtime—exists only to preserve generic type `T` in the type
* system. Always `undefined`.
*
* @internal
*/
protected readonly fake_expected_typed_value_?: T | undefined;
/**
* Creates a new TypeGuardError instance.
*
* @param props Error properties
*/
public constructor(props: TypeGuardError.IProps) {
// MESSAGE CONSTRUCTION
// Use custom message if provided, otherwise generate default format
super(
props.message ||
`Error on ${props.method}(): invalid type${
props.path ? ` on ${props.path}` : ""
}, expect to be ${props.expected}`,
);
// INHERITANCE POLYFILL
// Set up prototype for compatibility across different JavaScript environments
const proto = new.target.prototype;
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
else (this as any).__proto__ = proto;
// ASSIGN MEMBERS
this.method = props.method;
this.path = props.path;
this.expected = props.expected;
this.value = props.value;
if (props.description || props.value === undefined)
this.description =
props.description ??
[
"The value at this path is `undefined`.",
"",
`Please fill the \`${props.expected}\` typed value next time.`,
].join("\n");
}
}
export namespace TypeGuardError {
/** Properties for constructing a TypeGuardError. */
export interface IProps {
/**
* Name of the typia method that threw the error.
*
* E.g., `"typia.assert"`, `"typia.assertEquals"`.
*/
method: string;
/**
* Property path where assertion failed (optional).
*
* E.g., `"input.age"`, `"input.profile.email"`.
*/
path?: undefined | string;
/**
* String representation of expected type.
*
* E.g., `"string"`, `"number & ExclusiveMinimum<19>"`.
*/
expected: string;
/** Actual value that failed assertion. */
value: unknown;
/**
* Optional human-readable error description.
*
* For AI agent libraries or custom validation needing additional context.
*/
description?: string;
/**
* Custom error message (optional).
*
* If not provided, a default message is generated from other properties.
*/
message?: undefined | string;
}
}undefined
/**
* Validation result type with detailed error information.
*
* `IValidation<T>` is the return type of `typia.validate<T>()` and related
* validation functions. Unlike `typia.is<T>()` which returns a boolean, or
* `typia.assert<T>()` which throws exceptions, `typia.validate<T>()` returns
* this structured result with full error details.
*
* Check the {@link IValidation.success | success} discriminator:
*
* - `true` → {@link IValidation.ISuccess} with validated
* {@link IValidation.ISuccess.data | data}
* - `false` → {@link IValidation.IFailure} with
* {@link IValidation.IFailure.errors | errors} array
*
* This is the recommended validation function when you need to report
* validation errors to users or log them for debugging.
*
* @author Jeongho Nam - https://github.com/samchon
* @example
* const result = typia.validate<User>(input);
* if (result.success) {
* return result.data; // User type
* } else {
* result.errors.forEach((e) => console.log(e.path, e.expected));
* }
*
* @template T The expected type after successful validation
*/
export type IValidation<T = unknown> =
| IValidation.ISuccess<T>
| IValidation.IFailure;
export namespace IValidation {
/**
* Successful validation result.
*
* Indicates the input matches the expected type. The validated data is
* available in {@link data} with full type information.
*
* @template T The validated type
*/
export interface ISuccess<T = unknown> {
/**
* Success discriminator.
*
* Always `true` for successful validations. Use this to narrow the type
* before accessing {@link data}.
*/
success: true;
/**
* The validated data with correct type.
*
* The original input after successful validation. TypeScript will narrow
* this to type `T` when {@link success} is `true`.
*/
data: T;
}
/**
* Failed validation result with error details.
*
* Indicates the input did not match the expected type. Contains the original
* data and an array of all validation errors found.
*/
export interface IFailure {
/**
* Success discriminator.
*
* Always `false` for failed validations. Use this to narrow the type before
* accessing {@link errors}.
*/
success: false;
/**
* The original input that failed validation.
*
* Preserved as `unknown` type since it didn't match the expected type.
* Useful for debugging or logging the actual value.
*/
data: unknown;
/**
* Array of validation errors.
*
* Contains one entry for each validation failure found. Multiple errors may
* exist if the input has multiple type mismatches.
*/
errors: IError[];
}
/**
* Detailed information about a single validation error.
*
* Describes exactly what went wrong during validation, including the
* location, expected type, and actual value.
*/
export interface IError {
/**
* Property path to the error location.
*
* A dot-notation path from the root input to the failing property. Uses
* `$input` as the root. Example: `"$input.user.email"` or
* `"$input.items[0].price"`.
*/
path: string;
/**
* Expected type expression.
*
* A human-readable description of what type was expected at this location.
* Examples: `"string"`, `"number & ExclusiveMinimum<0>"`, `"(\"active\" |
* \"inactive\")"`.
*/
expected: string;
/**
* The actual value that failed validation.
*
* The value found at the error path. May be `undefined` if the property was
* missing. Useful for debugging type mismatches.
*/
value: unknown;
/**
* Human-readable error description.
*
* Optional additional context about the validation failure, such as
* constraint violations or custom error messages.
*/
description?: string;
}
}undefined
import { Equal } from "./internal/Equal";
import { IsTuple } from "./internal/IsTuple";
import { NativeClass } from "./internal/NativeClass";
import { ValueOf } from "./internal/ValueOf";
/**
* Converts a type to its resolved form by erasing all methods.
*
* `Resolved<T>` transforms classes to plain objects, extracts primitive values
* from boxed types (Boolean→boolean, Number→number, String→string), and
* recursively processes nested structures. Native classes (Date, Set, Map,
* etc.) are preserved unchanged.
*
* @author Jeongho Nam - https://github.com/samchon
* @author Kyungsu Kang - https://github.com/kakasoo
* @template T Target type to resolve
*/
export type Resolved<T> =
Equal<T, ResolvedMain<T>> extends true ? T : ResolvedMain<T>;
type ResolvedMain<T> = T extends [never]
? never // (special trick for jsonable | null) type
: ValueOf<T> extends boolean | number | bigint | string
? ValueOf<T>
: T extends Function
? never
: T extends object
? ResolvedObject<T>
: ValueOf<T>;
type ResolvedObject<T extends object> =
T extends Array<infer U>
? IsTuple<T> extends true
? ResolvedTuple<T>
: ResolvedMain<U>[]
: T extends Set<infer U>
? Set<ResolvedMain<U>>
: T extends Map<infer K, infer V>
? Map<ResolvedMain<K>, ResolvedMain<V>>
: T extends WeakSet<any> | WeakMap<any, any>
? never
: T extends NativeClass
? T
: {
[P in keyof T]: ResolvedMain<T[P]>;
};
type ResolvedTuple<T extends readonly any[]> = T extends []
? []
: T extends [infer F]
? [ResolvedMain<F>]
: T extends [infer F, ...infer Rest extends readonly any[]]
? [ResolvedMain<F>, ...ResolvedTuple<Rest>]
: T extends [(infer F)?]
? [ResolvedMain<F>?]
: T extends [(infer F)?, ...infer Rest extends readonly any[]]
? [ResolvedMain<F>?, ...ResolvedTuple<Rest>]
: [];Headers decoder (for express and fastify).
typia.http.headers<t>() is a function decoding an header instance, with automatic type casting to the expected type. When property type be defined as boolean or number type, typia.http.headers<t>() will cast the value to the expected type.
By the way, as HTTP headers are not enough to express complex data structures, typia.http.headers<t>() function has some limitations. If target type T is not following those restrictions, compilation errors would be occurred.
- Type T must be an object type
- Do not allow dynamic property
- Property key must be lower case
- Property value cannot be null, but undefined is possible
- Only boolean, bigint, number, string or their array types are allowed
- By the way, union type never be not allowed
- Property set-cookie must be array type
- Those properties cannot be array type
- age
- authorization
- content-length
- content-type
- etag
- expires
- from
- host
- if-modified-since
- if-unmodified-since
- last-modified
- location
- max-forwards
- proxy-authorization
- referer
- retry-after
- server
- user-agent
Also, typia.http.headers<t>() function does not perform validation about the decoded value. Therefore, if you can’t sure that input data is following the T type, it would better to call one of below functions instead.
typia.http.assertHeaders<T>():typia.assert<T>()+typia.http.headers<T>()typia.http.isHeaders<T>():typia.is<T>()+typia.http.headers<T>()typia.http.validateHeaders<T>():typia.validate<T>()+typia.http.headers<T>()
TypeScript Source Code
import typia from "typia";
interface IHeaders {
"x-Category": "x" | "y" | "z";
"x-MEMO"?: string;
"x-nAmE"?: string;
"x-Values": number[];
"x-FlAgS": boolean[];
"X-Descriptions": string[];
}
typia.http.createHeaders<IHeaders>();Compiled JavaScript File
import typia from "typia";
import * as __typia_transform__httpHeaderReadBoolean from "typia/lib/internal/_httpHeaderReadBoolean";
import * as __typia_transform__httpHeaderReadNumber from "typia/lib/internal/_httpHeaderReadNumber";
(() => {
return (input) => {
const output = {
"x-Category": input["x-category"],
"x-MEMO": input["x-memo"],
"x-nAmE": input["x-name"],
"x-Values": Array.isArray(input["x-values"])
? input["x-values"].map(
__typia_transform__httpHeaderReadNumber._httpHeaderReadNumber,
)
: (input["x-values"]
?.split(", ")
?.map(
__typia_transform__httpHeaderReadNumber._httpHeaderReadNumber,
) ?? []),
"x-FlAgS": Array.isArray(input["x-flags"])
? input["x-flags"].map(
__typia_transform__httpHeaderReadBoolean._httpHeaderReadBoolean,
)
: (input["x-flags"]
?.split(", ")
?.map(
__typia_transform__httpHeaderReadBoolean._httpHeaderReadBoolean,
) ?? []),
"X-Descriptions": Array.isArray(input["x-descriptions"])
? input["x-descriptions"].map((str) => str.trim())
: (input["x-descriptions"]?.split(", ")?.map((str) => str.trim()) ??
[]),
};
return output;
};
})();parameter() functions
undefined
export namespace http {
export function parameter<T extends Atomic.Type | null>(input: string): T;
export function createParameter<T extends Atomic.Type | null>(): (
input: string,
) => T;
}undefined
/**
* Error thrown when type assertion fails.
*
* Thrown by {@link assert}, {@link assertGuard}, and other assert-family
* functions when input doesn't match expected type `T`. Contains detailed
* information about the first assertion failure:
*
* - `method`: Which typia function threw (e.g., `"typia.assert"`)
* - `path`: Property path where error occurred (e.g., `"input.user.age"`)
* - `expected`: Expected type string (e.g., `"number & ExclusiveMinimum<19>"`)
* - `value`: Actual value that failed validation
*
* @template T Expected type (for type safety)
*/
export class TypeGuardError<T = any> extends Error {
/**
* Name of the typia method that threw this error.
*
* E.g., `"typia.assert"`, `"typia.assertEquals"`, `"typia.assertGuard"`.
*/
public readonly method: string;
/**
* Property path where assertion failed.
*
* Uses dot notation for nested properties. `undefined` if error occurred at
* root level.
*
* E.g., `"input.age"`, `"input.profile.email"`, `"input[0].name"`.
*/
public readonly path: string | undefined;
/**
* String representation of expected type.
*
* E.g., `"string"`, `"number & ExclusiveMinimum<19>"`, `"{ name: string; age:
* number }"`.
*/
public readonly expected: string;
/**
* Actual value that failed assertion.
*
* The raw value at the error path, useful for debugging.
*/
public readonly value: unknown;
/**
* Optional human-readable error description.
*
* Primarily for AI agent libraries or custom validation scenarios needing
* additional context. Standard assertions rely on `path`, `expected`, and
* `value` for error reporting.
*/
public readonly description?: string | undefined;
/**
* Phantom property for TypeScript type safety.
*
* Not used at runtime—exists only to preserve generic type `T` in the type
* system. Always `undefined`.
*
* @internal
*/
protected readonly fake_expected_typed_value_?: T | undefined;
/**
* Creates a new TypeGuardError instance.
*
* @param props Error properties
*/
public constructor(props: TypeGuardError.IProps) {
// MESSAGE CONSTRUCTION
// Use custom message if provided, otherwise generate default format
super(
props.message ||
`Error on ${props.method}(): invalid type${
props.path ? ` on ${props.path}` : ""
}, expect to be ${props.expected}`,
);
// INHERITANCE POLYFILL
// Set up prototype for compatibility across different JavaScript environments
const proto = new.target.prototype;
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
else (this as any).__proto__ = proto;
// ASSIGN MEMBERS
this.method = props.method;
this.path = props.path;
this.expected = props.expected;
this.value = props.value;
if (props.description || props.value === undefined)
this.description =
props.description ??
[
"The value at this path is `undefined`.",
"",
`Please fill the \`${props.expected}\` typed value next time.`,
].join("\n");
}
}
export namespace TypeGuardError {
/** Properties for constructing a TypeGuardError. */
export interface IProps {
/**
* Name of the typia method that threw the error.
*
* E.g., `"typia.assert"`, `"typia.assertEquals"`.
*/
method: string;
/**
* Property path where assertion failed (optional).
*
* E.g., `"input.age"`, `"input.profile.email"`.
*/
path?: undefined | string;
/**
* String representation of expected type.
*
* E.g., `"string"`, `"number & ExclusiveMinimum<19>"`.
*/
expected: string;
/** Actual value that failed assertion. */
value: unknown;
/**
* Optional human-readable error description.
*
* For AI agent libraries or custom validation needing additional context.
*/
description?: string;
/**
* Custom error message (optional).
*
* If not provided, a default message is generated from other properties.
*/
message?: undefined | string;
}
}URL path parameter decoder.
typia.http.parameter<T>() is a function decoding a path parameter, with automatic type casting to the expected type. When type T has been defined as boolean or number type, typia.http.parameter<T>() will cast the value to the expected type.
Also, typia.http.parameter<T>() performs type assertion to the decoded value by combining with assert function. Therefore, when the decoded value is not following the T type, TypeGuardError would be thrown.
TypeScript Source Code
import typia, { tags } from "typia";
typia.http.createParameter<string & tags.Format<"uuid">>();
typia.http.createParameter<number & tags.Type<"uint32">>();Compiled JavaScript File
import typia from "typia";
import * as __typia_transform__assertGuard from "typia/lib/internal/_assertGuard";
import * as __typia_transform__httpParameterReadNumber from "typia/lib/internal/_httpParameterReadNumber";
import * as __typia_transform__httpParameterReadString from "typia/lib/internal/_httpParameterReadString";
import * as __typia_transform__isFormatUuid from "typia/lib/internal/_isFormatUuid";
import * as __typia_transform__isTypeUint32 from "typia/lib/internal/_isTypeUint32";
(input) => {
const assert = (() => {
const __is = (input) =>
"string" === typeof input &&
__typia_transform__isFormatUuid._isFormatUuid(input);
let _errorFactory;
return (input, errorFactory) => {
if (false === __is(input)) {
_errorFactory = errorFactory;
((input, _path, _exceptionable = true) =>
("string" === typeof input &&
(__typia_transform__isFormatUuid._isFormatUuid(input) ||
__typia_transform__assertGuard._assertGuard(
true,
{
method: "typia.http.createParameter",
path: _path + "",
expected: 'string & Format<"uuid">',
value: input,
},
_errorFactory,
))) ||
__typia_transform__assertGuard._assertGuard(
true,
{
method: "typia.http.createParameter",
path: _path + "",
expected: '(string & Format<"uuid">)',
value: input,
},
_errorFactory,
))(input, "$input", true);
}
return input;
};
})();
const value =
__typia_transform__httpParameterReadString._httpParameterReadString(input);
return assert(value);
};
(input) => {
const assert = (() => {
const __is = (input) =>
"number" === typeof input &&
__typia_transform__isTypeUint32._isTypeUint32(input);
let _errorFactory;
return (input, errorFactory) => {
if (false === __is(input)) {
_errorFactory = errorFactory;
((input, _path, _exceptionable = true) =>
("number" === typeof input &&
(__typia_transform__isTypeUint32._isTypeUint32(input) ||
__typia_transform__assertGuard._assertGuard(
true,
{
method: "typia.http.createParameter",
path: _path + "",
expected: 'number & Type<"uint32">',
value: input,
},
_errorFactory,
))) ||
__typia_transform__assertGuard._assertGuard(
true,
{
method: "typia.http.createParameter",
path: _path + "",
expected: '(number & Type<"uint32">)',
value: input,
},
_errorFactory,
))(input, "$input", true);
}
return input;
};
})();
const value =
__typia_transform__httpParameterReadNumber._httpParameterReadNumber(input);
return assert(value);
};