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
/**
* Custom error class thrown when runtime assertion fails in `typia.assert<T>()` function.
*
* This error is thrown by the `typia.assert<T>()` function when the input value
* doesn't match the expected type.
*
* The error provides detailed information about the first assertion failure encountered,
* including the access path where the error occurred, the expected type, and the actual value.
*
* @template T - The expected type (generic for type safety)
* @author Jeongho Nam - https://github.com/samchon
* @example
* ```typescript
* interface IMember {
* name: string;
* age: number & ExclusiveMinimum<19>;
* }
*
* try {
* typia.assert<IMember>({ name: "John", age: 18 });
* } catch (error) {
* if (error instanceof TypeGuardError) {
* console.log(error.method); // "typia.assert"
* console.log(error.path); // "input.age"
* console.log(error.expected); // "number & ExclusiveMinimum<19>"
* console.log(error.value); // 18
* }
* }
* ```
*/
export class TypeGuardError<T = any> extends Error {
/**
* The name of the typia method that threw this error.
*
* @example "typia.assert"
*/
public readonly method: string;
/**
* The access path to the property where the assertion error occurred.
*
* Uses dot notation to indicate the path for nested object properties.
* May be `undefined` if the error occurred at the root level.
*
* @example
* - `"input.age"` - Error in the age property of the object
* - `"input.profile.email"` - Error in the email property of a nested object
* - `"input[0].name"` - Error in the name property of the first array element
* - `undefined` - Error occurred at the root level
*/
public readonly path: string | undefined;
/**
* String representation of the expected type at the error location.
*
* Represents TypeScript types as strings, including detailed type information
* for complex types.
*
* @example
* - `"string"` - Expected string type
* - `"number & ExclusiveMinimum<19>"` - Expected number greater than 19
* - `"undefined"` - Expected undefined (when superfluous property found in assertion)
* - `"{ name: string; age: number }"` - Expected object type
*/
public readonly expected: string;
/**
* The actual value that failed assertion.
*
* Stores the actual value at the error path as-is.
* Useful for debugging by comparing the expected type with the actual value.
*
* @example
* - `18` - Numeric value
* - `"invalid"` - String value
* - `{ name: "John", age: 18, sex: 1 }` - Object value
*/
public readonly value: unknown;
/**
* Phantom property for type safety purposes.
*
* This property is not actually used and exists only to maintain
* the generic type T in TypeScript's type system.
* Always has an `undefined` value at runtime.
*
* @internal
*/
protected readonly fake_expected_typed_value_?: T | undefined;
/**
* Creates a new TypeGuardError instance.
*
* @param props - Object containing the properties needed to create the error
*
* @example
* ```typescript
* const error = new TypeGuardError({
* method: "typia.assert",
* path: "input.age",
* expected: "number & ExclusiveMinimum<19>",
* value: 18
* });
* ```
*/
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;
}
}
export namespace TypeGuardError {
/**
* Interface for properties passed to the TypeGuardError constructor.
*
* @example
* ```typescript
* const props: TypeGuardError.IProps = {
* method: "typia.assertEquals",
* path: "input.sex",
* expected: "undefined",
* value: 1,
* message: "Custom error message" // optional
* };
* ```
*/
export interface IProps {
/**
* The name of the typia method that threw the error.
*
* @example "typia.assert", "typia.assertEquals"
*/
method: string;
/**
* The access path to the property where the assertion error occurred (optional).
*
* @example "input.age", "input.profile.email"
*/
path?: undefined | string;
/**
* String representation of the expected type at the error location.
*
* @example "string", "number & ExclusiveMinimum<19>"
*/
expected: string;
/**
* The actual value that failed assertion.
*/
value: unknown;
/**
* Custom error message (optional).
*
* If not provided, a default format message will be automatically generated.
*/
message?: undefined | string;
}
}
undefined
/**
* Union type representing the result of type validation
*
* This is the return type of {@link typia.validate} functions, returning
* {@link IValidation.ISuccess} on validation success and
* {@link IValidation.IFailure} on validation failure. When validation fails, it
* provides detailed, granular error information that precisely describes what
* went wrong, where it went wrong, and what was expected.
*
* This comprehensive error reporting makes `IValidation` particularly valuable
* for AI function calling scenarios, where Large Language Models (LLMs) need
* specific feedback to correct their parameter generation. The detailed error
* information is used by ILlmFunction.validate() to provide validation feedback
* to AI agents, enabling iterative correction and improvement of function
* calling accuracy.
*
* This type uses the Discriminated Union pattern, allowing type specification
* through the success property:
*
* ```typescript
* const result = typia.validate<string>(input);
* if (result.success) {
* // IValidation.ISuccess<string> type
* console.log(result.data); // validated data accessible
* } else {
* // IValidation.IFailure type
* console.log(result.errors); // detailed error information accessible
* }
* ```
*
* @author Jeongho Nam - https://github.com/samchon
* @template T The type to validate
*/
export type IValidation<T = unknown> =
| IValidation.ISuccess<T>
| IValidation.IFailure;
export namespace IValidation {
/**
* Interface returned when type validation succeeds
*
* Returned when the input value perfectly conforms to the specified type T.
* Since success is true, TypeScript's type guard allows safe access to the
* validated data through the data property.
*
* @template T The validated type
*/
export interface ISuccess<T = unknown> {
/** Indicates validation success */
success: true;
/** The validated data of type T */
data: T;
}
/**
* Interface returned when type validation fails
*
* Returned when the input value does not conform to the expected type.
* Contains comprehensive error information designed to be easily understood
* by both humans and AI systems. Each error in the errors array provides
* precise details about validation failures, including the exact path to the
* problematic property, what type was expected, and what value was actually
* provided.
*
* This detailed error structure is specifically optimized for AI function
* calling validation feedback. When LLMs make type errors during function
* calling, these granular error reports enable the AI to understand exactly
* what went wrong and how to fix it, improving success rates in subsequent
* attempts.
*
* Example error scenarios:
*
* - Type mismatch: expected "string" but got number 5
* - Format violation: expected "string & Format<'uuid'>" but got
* "invalid-format"
* - Missing properties: expected "required property 'name'" but got undefined
* - Array type errors: expected "Array<string>" but got single string value
*
* The errors are used by ILlmFunction.validate() to provide structured
* feedback to AI agents, enabling them to correct their parameter generation
* and achieve improved function calling accuracy.
*/
export interface IFailure {
/** Indicates validation failure */
success: false;
/** The original input data that failed validation */
data: unknown;
/** Array of detailed validation errors */
errors: IError[];
}
/**
* Detailed information about a specific validation error
*
* Each error provides granular, actionable information about validation
* failures, designed to be immediately useful for both human developers and
* AI systems. The error structure follows a consistent format that enables
* precise identification and correction of type mismatches.
*
* This error format is particularly valuable for AI function calling
* scenarios, where LLMs need to understand exactly what went wrong to
* generate correct parameters. The combination of path, expected type name,
* actual value, and optional human-readable description provides the AI with
* comprehensive context to make accurate corrections, which is why
* ILlmFunction.validate() can achieve such high success rates in validation
* feedback loops.
*
* The value field can contain any type of data, including `undefined` when
* dealing with missing required properties or null/undefined validation
* scenarios. This allows for precise error reporting in cases where the AI
* agent omits required fields or provides null/undefined values
* inappropriately.
*
* Real-world examples from AI function calling:
*
* {
* path: "$input.member.age",
* expected: "number",
* value: "25" // AI provided string instead of number
* }
*
* {
* path: "$input.count",
* expected: "number & Type<'uint32'>",
* value: 20.75 // AI provided float instead of uint32
* }
*
* {
* path: "$input.categories",
* expected: "Array<string>",
* value: "technology" // AI provided string instead of array
* }
*
* {
* path: "$input.id",
* expected: "string & Format<'uuid'>",
* value: "invalid-uuid-format" // AI provided malformed UUID
* }
*
* {
* path: "$input.user.name",
* expected: "string",
* value: undefined // AI omitted required property
* }
*/
export interface IError {
/**
* The path to the property that failed validation
*
* Dot-notation path using $input prefix indicating the exact location of
* the validation failure within the input object structure. Examples
* include "$input.member.age", "$input.categories[0]",
* "$input.user.profile.email"
*/
path: string;
/**
* The expected type name or type expression
*
* Technical type specification that describes what type was expected at
* this path. This follows TypeScript-like syntax with embedded constraint
* information, such as "string", "number & Type<'uint32'>",
* "Array<string>", "string & Format<'uuid'> & MinLength<8>", etc.
*/
expected: string;
/**
* The actual value that caused the validation failure
*
* This field contains the actual value that was provided but failed
* validation. Note that this value can be `undefined` in cases where a
* required property is missing or when validating against undefined
* values.
*/
value: unknown;
/**
* Optional human-readable description of the validation error
*
* This field is rarely populated in standard typia validation and is
* primarily intended for specialized AI agent libraries or custom
* validation scenarios that require additional context beyond the technical
* type information. Most validation errors rely solely on the path,
* expected, and value fields for comprehensive error reporting.
*/
description?: string;
}
}
undefined
import { Equal } from "./typings/Equal";
import { IsTuple } from "./typings/IsTuple";
import { NativeClass } from "./typings/NativeClass";
import { ValueOf } from "./typings/ValueOf";
/**
* Resolved type erased every methods.
*
* `Resolved` is a type of TMP (Type Meta Programming) type which converts
* its argument as a resolved type that erased every method properties.
*
* If the target argument is a built-in class which returns its origin primitive type
* through the `valueOf()` method like the `String` or `Number`, its return type would
* be the `string` or `number`. Otherwise, the built-in class does not have the
* `valueOf()` method, the return type would be same with the target argument.
*
* Otherwise, the target argument is a type of custom class, all of its custom methods
* would be erased and its prototype would be changed to the primitive `object`.
* Therefore, return type of the TMP type finally be the resolved object.
*
* Before | After
* ------------------------|----------------------------------------
* `Boolean` | `boolean`
* `Number` | `number`
* `BigInt` | `bigint`
* `String` | `string`
* `Class` | `interface`
* Native Class or Others | No change
*
* @template T Target argument type.
* @author Jeongho Nam - https://github.com/samchon
* @author Kyungsu Kang - https://github.com/kakasoo
*/
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.js";
import * as __typia_transform__randomArray from "typia/lib/internal/_randomArray.js";
import * as __typia_transform__randomFormatDate from "typia/lib/internal/_randomFormatDate.js";
import * as __typia_transform__randomFormatUuid from "typia/lib/internal/_randomFormatUuid.js";
import * as __typia_transform__randomInteger from "typia/lib/internal/_randomInteger.js";
import * as __typia_transform__randomNumber from "typia/lib/internal/_randomNumber.js";
import * as __typia_transform__randomString from "typia/lib/internal/_randomString.js";
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 &&
Number.isFinite(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 &&
Number.isFinite(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
/**
* Custom error class thrown when runtime assertion fails in `typia.assert<T>()` function.
*
* This error is thrown by the `typia.assert<T>()` function when the input value
* doesn't match the expected type.
*
* The error provides detailed information about the first assertion failure encountered,
* including the access path where the error occurred, the expected type, and the actual value.
*
* @template T - The expected type (generic for type safety)
* @author Jeongho Nam - https://github.com/samchon
* @example
* ```typescript
* interface IMember {
* name: string;
* age: number & ExclusiveMinimum<19>;
* }
*
* try {
* typia.assert<IMember>({ name: "John", age: 18 });
* } catch (error) {
* if (error instanceof TypeGuardError) {
* console.log(error.method); // "typia.assert"
* console.log(error.path); // "input.age"
* console.log(error.expected); // "number & ExclusiveMinimum<19>"
* console.log(error.value); // 18
* }
* }
* ```
*/
export class TypeGuardError<T = any> extends Error {
/**
* The name of the typia method that threw this error.
*
* @example "typia.assert"
*/
public readonly method: string;
/**
* The access path to the property where the assertion error occurred.
*
* Uses dot notation to indicate the path for nested object properties.
* May be `undefined` if the error occurred at the root level.
*
* @example
* - `"input.age"` - Error in the age property of the object
* - `"input.profile.email"` - Error in the email property of a nested object
* - `"input[0].name"` - Error in the name property of the first array element
* - `undefined` - Error occurred at the root level
*/
public readonly path: string | undefined;
/**
* String representation of the expected type at the error location.
*
* Represents TypeScript types as strings, including detailed type information
* for complex types.
*
* @example
* - `"string"` - Expected string type
* - `"number & ExclusiveMinimum<19>"` - Expected number greater than 19
* - `"undefined"` - Expected undefined (when superfluous property found in assertion)
* - `"{ name: string; age: number }"` - Expected object type
*/
public readonly expected: string;
/**
* The actual value that failed assertion.
*
* Stores the actual value at the error path as-is.
* Useful for debugging by comparing the expected type with the actual value.
*
* @example
* - `18` - Numeric value
* - `"invalid"` - String value
* - `{ name: "John", age: 18, sex: 1 }` - Object value
*/
public readonly value: unknown;
/**
* Phantom property for type safety purposes.
*
* This property is not actually used and exists only to maintain
* the generic type T in TypeScript's type system.
* Always has an `undefined` value at runtime.
*
* @internal
*/
protected readonly fake_expected_typed_value_?: T | undefined;
/**
* Creates a new TypeGuardError instance.
*
* @param props - Object containing the properties needed to create the error
*
* @example
* ```typescript
* const error = new TypeGuardError({
* method: "typia.assert",
* path: "input.age",
* expected: "number & ExclusiveMinimum<19>",
* value: 18
* });
* ```
*/
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;
}
}
export namespace TypeGuardError {
/**
* Interface for properties passed to the TypeGuardError constructor.
*
* @example
* ```typescript
* const props: TypeGuardError.IProps = {
* method: "typia.assertEquals",
* path: "input.sex",
* expected: "undefined",
* value: 1,
* message: "Custom error message" // optional
* };
* ```
*/
export interface IProps {
/**
* The name of the typia method that threw the error.
*
* @example "typia.assert", "typia.assertEquals"
*/
method: string;
/**
* The access path to the property where the assertion error occurred (optional).
*
* @example "input.age", "input.profile.email"
*/
path?: undefined | string;
/**
* String representation of the expected type at the error location.
*
* @example "string", "number & ExclusiveMinimum<19>"
*/
expected: string;
/**
* The actual value that failed assertion.
*/
value: unknown;
/**
* Custom error message (optional).
*
* If not provided, a default format message will be automatically generated.
*/
message?: undefined | string;
}
}
undefined
/**
* Union type representing the result of type validation
*
* This is the return type of {@link typia.validate} functions, returning
* {@link IValidation.ISuccess} on validation success and
* {@link IValidation.IFailure} on validation failure. When validation fails, it
* provides detailed, granular error information that precisely describes what
* went wrong, where it went wrong, and what was expected.
*
* This comprehensive error reporting makes `IValidation` particularly valuable
* for AI function calling scenarios, where Large Language Models (LLMs) need
* specific feedback to correct their parameter generation. The detailed error
* information is used by ILlmFunction.validate() to provide validation feedback
* to AI agents, enabling iterative correction and improvement of function
* calling accuracy.
*
* This type uses the Discriminated Union pattern, allowing type specification
* through the success property:
*
* ```typescript
* const result = typia.validate<string>(input);
* if (result.success) {
* // IValidation.ISuccess<string> type
* console.log(result.data); // validated data accessible
* } else {
* // IValidation.IFailure type
* console.log(result.errors); // detailed error information accessible
* }
* ```
*
* @author Jeongho Nam - https://github.com/samchon
* @template T The type to validate
*/
export type IValidation<T = unknown> =
| IValidation.ISuccess<T>
| IValidation.IFailure;
export namespace IValidation {
/**
* Interface returned when type validation succeeds
*
* Returned when the input value perfectly conforms to the specified type T.
* Since success is true, TypeScript's type guard allows safe access to the
* validated data through the data property.
*
* @template T The validated type
*/
export interface ISuccess<T = unknown> {
/** Indicates validation success */
success: true;
/** The validated data of type T */
data: T;
}
/**
* Interface returned when type validation fails
*
* Returned when the input value does not conform to the expected type.
* Contains comprehensive error information designed to be easily understood
* by both humans and AI systems. Each error in the errors array provides
* precise details about validation failures, including the exact path to the
* problematic property, what type was expected, and what value was actually
* provided.
*
* This detailed error structure is specifically optimized for AI function
* calling validation feedback. When LLMs make type errors during function
* calling, these granular error reports enable the AI to understand exactly
* what went wrong and how to fix it, improving success rates in subsequent
* attempts.
*
* Example error scenarios:
*
* - Type mismatch: expected "string" but got number 5
* - Format violation: expected "string & Format<'uuid'>" but got
* "invalid-format"
* - Missing properties: expected "required property 'name'" but got undefined
* - Array type errors: expected "Array<string>" but got single string value
*
* The errors are used by ILlmFunction.validate() to provide structured
* feedback to AI agents, enabling them to correct their parameter generation
* and achieve improved function calling accuracy.
*/
export interface IFailure {
/** Indicates validation failure */
success: false;
/** The original input data that failed validation */
data: unknown;
/** Array of detailed validation errors */
errors: IError[];
}
/**
* Detailed information about a specific validation error
*
* Each error provides granular, actionable information about validation
* failures, designed to be immediately useful for both human developers and
* AI systems. The error structure follows a consistent format that enables
* precise identification and correction of type mismatches.
*
* This error format is particularly valuable for AI function calling
* scenarios, where LLMs need to understand exactly what went wrong to
* generate correct parameters. The combination of path, expected type name,
* actual value, and optional human-readable description provides the AI with
* comprehensive context to make accurate corrections, which is why
* ILlmFunction.validate() can achieve such high success rates in validation
* feedback loops.
*
* The value field can contain any type of data, including `undefined` when
* dealing with missing required properties or null/undefined validation
* scenarios. This allows for precise error reporting in cases where the AI
* agent omits required fields or provides null/undefined values
* inappropriately.
*
* Real-world examples from AI function calling:
*
* {
* path: "$input.member.age",
* expected: "number",
* value: "25" // AI provided string instead of number
* }
*
* {
* path: "$input.count",
* expected: "number & Type<'uint32'>",
* value: 20.75 // AI provided float instead of uint32
* }
*
* {
* path: "$input.categories",
* expected: "Array<string>",
* value: "technology" // AI provided string instead of array
* }
*
* {
* path: "$input.id",
* expected: "string & Format<'uuid'>",
* value: "invalid-uuid-format" // AI provided malformed UUID
* }
*
* {
* path: "$input.user.name",
* expected: "string",
* value: undefined // AI omitted required property
* }
*/
export interface IError {
/**
* The path to the property that failed validation
*
* Dot-notation path using $input prefix indicating the exact location of
* the validation failure within the input object structure. Examples
* include "$input.member.age", "$input.categories[0]",
* "$input.user.profile.email"
*/
path: string;
/**
* The expected type name or type expression
*
* Technical type specification that describes what type was expected at
* this path. This follows TypeScript-like syntax with embedded constraint
* information, such as "string", "number & Type<'uint32'>",
* "Array<string>", "string & Format<'uuid'> & MinLength<8>", etc.
*/
expected: string;
/**
* The actual value that caused the validation failure
*
* This field contains the actual value that was provided but failed
* validation. Note that this value can be `undefined` in cases where a
* required property is missing or when validating against undefined
* values.
*/
value: unknown;
/**
* Optional human-readable description of the validation error
*
* This field is rarely populated in standard typia validation and is
* primarily intended for specialized AI agent libraries or custom
* validation scenarios that require additional context beyond the technical
* type information. Most validation errors rely solely on the path,
* expected, and value fields for comprehensive error reporting.
*/
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.js";
import * as __typia_transform__randomArray from "typia/lib/internal/_randomArray.js";
import * as __typia_transform__randomFormatDate from "typia/lib/internal/_randomFormatDate.js";
import * as __typia_transform__randomFormatUuid from "typia/lib/internal/_randomFormatUuid.js";
import * as __typia_transform__randomInteger from "typia/lib/internal/_randomInteger.js";
import * as __typia_transform__randomNumber from "typia/lib/internal/_randomNumber.js";
import * as __typia_transform__randomString from "typia/lib/internal/_randomString.js";
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 &&
Number.isFinite(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 &&
Number.isFinite(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
/**
* Custom error class thrown when runtime assertion fails in `typia.assert<T>()` function.
*
* This error is thrown by the `typia.assert<T>()` function when the input value
* doesn't match the expected type.
*
* The error provides detailed information about the first assertion failure encountered,
* including the access path where the error occurred, the expected type, and the actual value.
*
* @template T - The expected type (generic for type safety)
* @author Jeongho Nam - https://github.com/samchon
* @example
* ```typescript
* interface IMember {
* name: string;
* age: number & ExclusiveMinimum<19>;
* }
*
* try {
* typia.assert<IMember>({ name: "John", age: 18 });
* } catch (error) {
* if (error instanceof TypeGuardError) {
* console.log(error.method); // "typia.assert"
* console.log(error.path); // "input.age"
* console.log(error.expected); // "number & ExclusiveMinimum<19>"
* console.log(error.value); // 18
* }
* }
* ```
*/
export class TypeGuardError<T = any> extends Error {
/**
* The name of the typia method that threw this error.
*
* @example "typia.assert"
*/
public readonly method: string;
/**
* The access path to the property where the assertion error occurred.
*
* Uses dot notation to indicate the path for nested object properties.
* May be `undefined` if the error occurred at the root level.
*
* @example
* - `"input.age"` - Error in the age property of the object
* - `"input.profile.email"` - Error in the email property of a nested object
* - `"input[0].name"` - Error in the name property of the first array element
* - `undefined` - Error occurred at the root level
*/
public readonly path: string | undefined;
/**
* String representation of the expected type at the error location.
*
* Represents TypeScript types as strings, including detailed type information
* for complex types.
*
* @example
* - `"string"` - Expected string type
* - `"number & ExclusiveMinimum<19>"` - Expected number greater than 19
* - `"undefined"` - Expected undefined (when superfluous property found in assertion)
* - `"{ name: string; age: number }"` - Expected object type
*/
public readonly expected: string;
/**
* The actual value that failed assertion.
*
* Stores the actual value at the error path as-is.
* Useful for debugging by comparing the expected type with the actual value.
*
* @example
* - `18` - Numeric value
* - `"invalid"` - String value
* - `{ name: "John", age: 18, sex: 1 }` - Object value
*/
public readonly value: unknown;
/**
* Phantom property for type safety purposes.
*
* This property is not actually used and exists only to maintain
* the generic type T in TypeScript's type system.
* Always has an `undefined` value at runtime.
*
* @internal
*/
protected readonly fake_expected_typed_value_?: T | undefined;
/**
* Creates a new TypeGuardError instance.
*
* @param props - Object containing the properties needed to create the error
*
* @example
* ```typescript
* const error = new TypeGuardError({
* method: "typia.assert",
* path: "input.age",
* expected: "number & ExclusiveMinimum<19>",
* value: 18
* });
* ```
*/
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;
}
}
export namespace TypeGuardError {
/**
* Interface for properties passed to the TypeGuardError constructor.
*
* @example
* ```typescript
* const props: TypeGuardError.IProps = {
* method: "typia.assertEquals",
* path: "input.sex",
* expected: "undefined",
* value: 1,
* message: "Custom error message" // optional
* };
* ```
*/
export interface IProps {
/**
* The name of the typia method that threw the error.
*
* @example "typia.assert", "typia.assertEquals"
*/
method: string;
/**
* The access path to the property where the assertion error occurred (optional).
*
* @example "input.age", "input.profile.email"
*/
path?: undefined | string;
/**
* String representation of the expected type at the error location.
*
* @example "string", "number & ExclusiveMinimum<19>"
*/
expected: string;
/**
* The actual value that failed assertion.
*/
value: unknown;
/**
* Custom error message (optional).
*
* If not provided, a default format message will be automatically generated.
*/
message?: undefined | string;
}
}
undefined
/**
* Union type representing the result of type validation
*
* This is the return type of {@link typia.validate} functions, returning
* {@link IValidation.ISuccess} on validation success and
* {@link IValidation.IFailure} on validation failure. When validation fails, it
* provides detailed, granular error information that precisely describes what
* went wrong, where it went wrong, and what was expected.
*
* This comprehensive error reporting makes `IValidation` particularly valuable
* for AI function calling scenarios, where Large Language Models (LLMs) need
* specific feedback to correct their parameter generation. The detailed error
* information is used by ILlmFunction.validate() to provide validation feedback
* to AI agents, enabling iterative correction and improvement of function
* calling accuracy.
*
* This type uses the Discriminated Union pattern, allowing type specification
* through the success property:
*
* ```typescript
* const result = typia.validate<string>(input);
* if (result.success) {
* // IValidation.ISuccess<string> type
* console.log(result.data); // validated data accessible
* } else {
* // IValidation.IFailure type
* console.log(result.errors); // detailed error information accessible
* }
* ```
*
* @author Jeongho Nam - https://github.com/samchon
* @template T The type to validate
*/
export type IValidation<T = unknown> =
| IValidation.ISuccess<T>
| IValidation.IFailure;
export namespace IValidation {
/**
* Interface returned when type validation succeeds
*
* Returned when the input value perfectly conforms to the specified type T.
* Since success is true, TypeScript's type guard allows safe access to the
* validated data through the data property.
*
* @template T The validated type
*/
export interface ISuccess<T = unknown> {
/** Indicates validation success */
success: true;
/** The validated data of type T */
data: T;
}
/**
* Interface returned when type validation fails
*
* Returned when the input value does not conform to the expected type.
* Contains comprehensive error information designed to be easily understood
* by both humans and AI systems. Each error in the errors array provides
* precise details about validation failures, including the exact path to the
* problematic property, what type was expected, and what value was actually
* provided.
*
* This detailed error structure is specifically optimized for AI function
* calling validation feedback. When LLMs make type errors during function
* calling, these granular error reports enable the AI to understand exactly
* what went wrong and how to fix it, improving success rates in subsequent
* attempts.
*
* Example error scenarios:
*
* - Type mismatch: expected "string" but got number 5
* - Format violation: expected "string & Format<'uuid'>" but got
* "invalid-format"
* - Missing properties: expected "required property 'name'" but got undefined
* - Array type errors: expected "Array<string>" but got single string value
*
* The errors are used by ILlmFunction.validate() to provide structured
* feedback to AI agents, enabling them to correct their parameter generation
* and achieve improved function calling accuracy.
*/
export interface IFailure {
/** Indicates validation failure */
success: false;
/** The original input data that failed validation */
data: unknown;
/** Array of detailed validation errors */
errors: IError[];
}
/**
* Detailed information about a specific validation error
*
* Each error provides granular, actionable information about validation
* failures, designed to be immediately useful for both human developers and
* AI systems. The error structure follows a consistent format that enables
* precise identification and correction of type mismatches.
*
* This error format is particularly valuable for AI function calling
* scenarios, where LLMs need to understand exactly what went wrong to
* generate correct parameters. The combination of path, expected type name,
* actual value, and optional human-readable description provides the AI with
* comprehensive context to make accurate corrections, which is why
* ILlmFunction.validate() can achieve such high success rates in validation
* feedback loops.
*
* The value field can contain any type of data, including `undefined` when
* dealing with missing required properties or null/undefined validation
* scenarios. This allows for precise error reporting in cases where the AI
* agent omits required fields or provides null/undefined values
* inappropriately.
*
* Real-world examples from AI function calling:
*
* {
* path: "$input.member.age",
* expected: "number",
* value: "25" // AI provided string instead of number
* }
*
* {
* path: "$input.count",
* expected: "number & Type<'uint32'>",
* value: 20.75 // AI provided float instead of uint32
* }
*
* {
* path: "$input.categories",
* expected: "Array<string>",
* value: "technology" // AI provided string instead of array
* }
*
* {
* path: "$input.id",
* expected: "string & Format<'uuid'>",
* value: "invalid-uuid-format" // AI provided malformed UUID
* }
*
* {
* path: "$input.user.name",
* expected: "string",
* value: undefined // AI omitted required property
* }
*/
export interface IError {
/**
* The path to the property that failed validation
*
* Dot-notation path using $input prefix indicating the exact location of
* the validation failure within the input object structure. Examples
* include "$input.member.age", "$input.categories[0]",
* "$input.user.profile.email"
*/
path: string;
/**
* The expected type name or type expression
*
* Technical type specification that describes what type was expected at
* this path. This follows TypeScript-like syntax with embedded constraint
* information, such as "string", "number & Type<'uint32'>",
* "Array<string>", "string & Format<'uuid'> & MinLength<8>", etc.
*/
expected: string;
/**
* The actual value that caused the validation failure
*
* This field contains the actual value that was provided but failed
* validation. Note that this value can be `undefined` in cases where a
* required property is missing or when validating against undefined
* values.
*/
value: unknown;
/**
* Optional human-readable description of the validation error
*
* This field is rarely populated in standard typia validation and is
* primarily intended for specialized AI agent libraries or custom
* validation scenarios that require additional context beyond the technical
* type information. Most validation errors rely solely on the path,
* expected, and value fields for comprehensive error reporting.
*/
description?: string;
}
}
undefined
import { Equal } from "./typings/Equal";
import { IsTuple } from "./typings/IsTuple";
import { NativeClass } from "./typings/NativeClass";
import { ValueOf } from "./typings/ValueOf";
/**
* Camel case type.
*
* `CamelCase` type is a type that all keys of an object are camelized.
*
* It also erase every method properties like {@link Resolved} type.
*
* @template T Target type to be camelized
* @author Jeongho Nam - https://github.com/samchon
*/
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
/**
* Custom error class thrown when runtime assertion fails in `typia.assert<T>()` function.
*
* This error is thrown by the `typia.assert<T>()` function when the input value
* doesn't match the expected type.
*
* The error provides detailed information about the first assertion failure encountered,
* including the access path where the error occurred, the expected type, and the actual value.
*
* @template T - The expected type (generic for type safety)
* @author Jeongho Nam - https://github.com/samchon
* @example
* ```typescript
* interface IMember {
* name: string;
* age: number & ExclusiveMinimum<19>;
* }
*
* try {
* typia.assert<IMember>({ name: "John", age: 18 });
* } catch (error) {
* if (error instanceof TypeGuardError) {
* console.log(error.method); // "typia.assert"
* console.log(error.path); // "input.age"
* console.log(error.expected); // "number & ExclusiveMinimum<19>"
* console.log(error.value); // 18
* }
* }
* ```
*/
export class TypeGuardError<T = any> extends Error {
/**
* The name of the typia method that threw this error.
*
* @example "typia.assert"
*/
public readonly method: string;
/**
* The access path to the property where the assertion error occurred.
*
* Uses dot notation to indicate the path for nested object properties.
* May be `undefined` if the error occurred at the root level.
*
* @example
* - `"input.age"` - Error in the age property of the object
* - `"input.profile.email"` - Error in the email property of a nested object
* - `"input[0].name"` - Error in the name property of the first array element
* - `undefined` - Error occurred at the root level
*/
public readonly path: string | undefined;
/**
* String representation of the expected type at the error location.
*
* Represents TypeScript types as strings, including detailed type information
* for complex types.
*
* @example
* - `"string"` - Expected string type
* - `"number & ExclusiveMinimum<19>"` - Expected number greater than 19
* - `"undefined"` - Expected undefined (when superfluous property found in assertion)
* - `"{ name: string; age: number }"` - Expected object type
*/
public readonly expected: string;
/**
* The actual value that failed assertion.
*
* Stores the actual value at the error path as-is.
* Useful for debugging by comparing the expected type with the actual value.
*
* @example
* - `18` - Numeric value
* - `"invalid"` - String value
* - `{ name: "John", age: 18, sex: 1 }` - Object value
*/
public readonly value: unknown;
/**
* Phantom property for type safety purposes.
*
* This property is not actually used and exists only to maintain
* the generic type T in TypeScript's type system.
* Always has an `undefined` value at runtime.
*
* @internal
*/
protected readonly fake_expected_typed_value_?: T | undefined;
/**
* Creates a new TypeGuardError instance.
*
* @param props - Object containing the properties needed to create the error
*
* @example
* ```typescript
* const error = new TypeGuardError({
* method: "typia.assert",
* path: "input.age",
* expected: "number & ExclusiveMinimum<19>",
* value: 18
* });
* ```
*/
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;
}
}
export namespace TypeGuardError {
/**
* Interface for properties passed to the TypeGuardError constructor.
*
* @example
* ```typescript
* const props: TypeGuardError.IProps = {
* method: "typia.assertEquals",
* path: "input.sex",
* expected: "undefined",
* value: 1,
* message: "Custom error message" // optional
* };
* ```
*/
export interface IProps {
/**
* The name of the typia method that threw the error.
*
* @example "typia.assert", "typia.assertEquals"
*/
method: string;
/**
* The access path to the property where the assertion error occurred (optional).
*
* @example "input.age", "input.profile.email"
*/
path?: undefined | string;
/**
* String representation of the expected type at the error location.
*
* @example "string", "number & ExclusiveMinimum<19>"
*/
expected: string;
/**
* The actual value that failed assertion.
*/
value: unknown;
/**
* Custom error message (optional).
*
* If not provided, a default format message will be automatically generated.
*/
message?: undefined | string;
}
}
undefined
/**
* Union type representing the result of type validation
*
* This is the return type of {@link typia.validate} functions, returning
* {@link IValidation.ISuccess} on validation success and
* {@link IValidation.IFailure} on validation failure. When validation fails, it
* provides detailed, granular error information that precisely describes what
* went wrong, where it went wrong, and what was expected.
*
* This comprehensive error reporting makes `IValidation` particularly valuable
* for AI function calling scenarios, where Large Language Models (LLMs) need
* specific feedback to correct their parameter generation. The detailed error
* information is used by ILlmFunction.validate() to provide validation feedback
* to AI agents, enabling iterative correction and improvement of function
* calling accuracy.
*
* This type uses the Discriminated Union pattern, allowing type specification
* through the success property:
*
* ```typescript
* const result = typia.validate<string>(input);
* if (result.success) {
* // IValidation.ISuccess<string> type
* console.log(result.data); // validated data accessible
* } else {
* // IValidation.IFailure type
* console.log(result.errors); // detailed error information accessible
* }
* ```
*
* @author Jeongho Nam - https://github.com/samchon
* @template T The type to validate
*/
export type IValidation<T = unknown> =
| IValidation.ISuccess<T>
| IValidation.IFailure;
export namespace IValidation {
/**
* Interface returned when type validation succeeds
*
* Returned when the input value perfectly conforms to the specified type T.
* Since success is true, TypeScript's type guard allows safe access to the
* validated data through the data property.
*
* @template T The validated type
*/
export interface ISuccess<T = unknown> {
/** Indicates validation success */
success: true;
/** The validated data of type T */
data: T;
}
/**
* Interface returned when type validation fails
*
* Returned when the input value does not conform to the expected type.
* Contains comprehensive error information designed to be easily understood
* by both humans and AI systems. Each error in the errors array provides
* precise details about validation failures, including the exact path to the
* problematic property, what type was expected, and what value was actually
* provided.
*
* This detailed error structure is specifically optimized for AI function
* calling validation feedback. When LLMs make type errors during function
* calling, these granular error reports enable the AI to understand exactly
* what went wrong and how to fix it, improving success rates in subsequent
* attempts.
*
* Example error scenarios:
*
* - Type mismatch: expected "string" but got number 5
* - Format violation: expected "string & Format<'uuid'>" but got
* "invalid-format"
* - Missing properties: expected "required property 'name'" but got undefined
* - Array type errors: expected "Array<string>" but got single string value
*
* The errors are used by ILlmFunction.validate() to provide structured
* feedback to AI agents, enabling them to correct their parameter generation
* and achieve improved function calling accuracy.
*/
export interface IFailure {
/** Indicates validation failure */
success: false;
/** The original input data that failed validation */
data: unknown;
/** Array of detailed validation errors */
errors: IError[];
}
/**
* Detailed information about a specific validation error
*
* Each error provides granular, actionable information about validation
* failures, designed to be immediately useful for both human developers and
* AI systems. The error structure follows a consistent format that enables
* precise identification and correction of type mismatches.
*
* This error format is particularly valuable for AI function calling
* scenarios, where LLMs need to understand exactly what went wrong to
* generate correct parameters. The combination of path, expected type name,
* actual value, and optional human-readable description provides the AI with
* comprehensive context to make accurate corrections, which is why
* ILlmFunction.validate() can achieve such high success rates in validation
* feedback loops.
*
* The value field can contain any type of data, including `undefined` when
* dealing with missing required properties or null/undefined validation
* scenarios. This allows for precise error reporting in cases where the AI
* agent omits required fields or provides null/undefined values
* inappropriately.
*
* Real-world examples from AI function calling:
*
* {
* path: "$input.member.age",
* expected: "number",
* value: "25" // AI provided string instead of number
* }
*
* {
* path: "$input.count",
* expected: "number & Type<'uint32'>",
* value: 20.75 // AI provided float instead of uint32
* }
*
* {
* path: "$input.categories",
* expected: "Array<string>",
* value: "technology" // AI provided string instead of array
* }
*
* {
* path: "$input.id",
* expected: "string & Format<'uuid'>",
* value: "invalid-uuid-format" // AI provided malformed UUID
* }
*
* {
* path: "$input.user.name",
* expected: "string",
* value: undefined // AI omitted required property
* }
*/
export interface IError {
/**
* The path to the property that failed validation
*
* Dot-notation path using $input prefix indicating the exact location of
* the validation failure within the input object structure. Examples
* include "$input.member.age", "$input.categories[0]",
* "$input.user.profile.email"
*/
path: string;
/**
* The expected type name or type expression
*
* Technical type specification that describes what type was expected at
* this path. This follows TypeScript-like syntax with embedded constraint
* information, such as "string", "number & Type<'uint32'>",
* "Array<string>", "string & Format<'uuid'> & MinLength<8>", etc.
*/
expected: string;
/**
* The actual value that caused the validation failure
*
* This field contains the actual value that was provided but failed
* validation. Note that this value can be `undefined` in cases where a
* required property is missing or when validating against undefined
* values.
*/
value: unknown;
/**
* Optional human-readable description of the validation error
*
* This field is rarely populated in standard typia validation and is
* primarily intended for specialized AI agent libraries or custom
* validation scenarios that require additional context beyond the technical
* type information. Most validation errors rely solely on the path,
* expected, and value fields for comprehensive error reporting.
*/
description?: string;
}
}
undefined
import { Equal } from "./typings/Equal";
import { IsTuple } from "./typings/IsTuple";
import { NativeClass } from "./typings/NativeClass";
import { ValueOf } from "./typings/ValueOf";
/**
* Pascal case type.
*
* `PascalCase` type is a type that all keys of an object are pascalized.
*
* It also erase every method properties like {@link Resolved} type.
*
* @template T Target type to be pascalized
* @author Jeongho Nam - https://github.com/samchon
*/
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
/**
* Custom error class thrown when runtime assertion fails in `typia.assert<T>()` function.
*
* This error is thrown by the `typia.assert<T>()` function when the input value
* doesn't match the expected type.
*
* The error provides detailed information about the first assertion failure encountered,
* including the access path where the error occurred, the expected type, and the actual value.
*
* @template T - The expected type (generic for type safety)
* @author Jeongho Nam - https://github.com/samchon
* @example
* ```typescript
* interface IMember {
* name: string;
* age: number & ExclusiveMinimum<19>;
* }
*
* try {
* typia.assert<IMember>({ name: "John", age: 18 });
* } catch (error) {
* if (error instanceof TypeGuardError) {
* console.log(error.method); // "typia.assert"
* console.log(error.path); // "input.age"
* console.log(error.expected); // "number & ExclusiveMinimum<19>"
* console.log(error.value); // 18
* }
* }
* ```
*/
export class TypeGuardError<T = any> extends Error {
/**
* The name of the typia method that threw this error.
*
* @example "typia.assert"
*/
public readonly method: string;
/**
* The access path to the property where the assertion error occurred.
*
* Uses dot notation to indicate the path for nested object properties.
* May be `undefined` if the error occurred at the root level.
*
* @example
* - `"input.age"` - Error in the age property of the object
* - `"input.profile.email"` - Error in the email property of a nested object
* - `"input[0].name"` - Error in the name property of the first array element
* - `undefined` - Error occurred at the root level
*/
public readonly path: string | undefined;
/**
* String representation of the expected type at the error location.
*
* Represents TypeScript types as strings, including detailed type information
* for complex types.
*
* @example
* - `"string"` - Expected string type
* - `"number & ExclusiveMinimum<19>"` - Expected number greater than 19
* - `"undefined"` - Expected undefined (when superfluous property found in assertion)
* - `"{ name: string; age: number }"` - Expected object type
*/
public readonly expected: string;
/**
* The actual value that failed assertion.
*
* Stores the actual value at the error path as-is.
* Useful for debugging by comparing the expected type with the actual value.
*
* @example
* - `18` - Numeric value
* - `"invalid"` - String value
* - `{ name: "John", age: 18, sex: 1 }` - Object value
*/
public readonly value: unknown;
/**
* Phantom property for type safety purposes.
*
* This property is not actually used and exists only to maintain
* the generic type T in TypeScript's type system.
* Always has an `undefined` value at runtime.
*
* @internal
*/
protected readonly fake_expected_typed_value_?: T | undefined;
/**
* Creates a new TypeGuardError instance.
*
* @param props - Object containing the properties needed to create the error
*
* @example
* ```typescript
* const error = new TypeGuardError({
* method: "typia.assert",
* path: "input.age",
* expected: "number & ExclusiveMinimum<19>",
* value: 18
* });
* ```
*/
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;
}
}
export namespace TypeGuardError {
/**
* Interface for properties passed to the TypeGuardError constructor.
*
* @example
* ```typescript
* const props: TypeGuardError.IProps = {
* method: "typia.assertEquals",
* path: "input.sex",
* expected: "undefined",
* value: 1,
* message: "Custom error message" // optional
* };
* ```
*/
export interface IProps {
/**
* The name of the typia method that threw the error.
*
* @example "typia.assert", "typia.assertEquals"
*/
method: string;
/**
* The access path to the property where the assertion error occurred (optional).
*
* @example "input.age", "input.profile.email"
*/
path?: undefined | string;
/**
* String representation of the expected type at the error location.
*
* @example "string", "number & ExclusiveMinimum<19>"
*/
expected: string;
/**
* The actual value that failed assertion.
*/
value: unknown;
/**
* Custom error message (optional).
*
* If not provided, a default format message will be automatically generated.
*/
message?: undefined | string;
}
}
undefined
/**
* Union type representing the result of type validation
*
* This is the return type of {@link typia.validate} functions, returning
* {@link IValidation.ISuccess} on validation success and
* {@link IValidation.IFailure} on validation failure. When validation fails, it
* provides detailed, granular error information that precisely describes what
* went wrong, where it went wrong, and what was expected.
*
* This comprehensive error reporting makes `IValidation` particularly valuable
* for AI function calling scenarios, where Large Language Models (LLMs) need
* specific feedback to correct their parameter generation. The detailed error
* information is used by ILlmFunction.validate() to provide validation feedback
* to AI agents, enabling iterative correction and improvement of function
* calling accuracy.
*
* This type uses the Discriminated Union pattern, allowing type specification
* through the success property:
*
* ```typescript
* const result = typia.validate<string>(input);
* if (result.success) {
* // IValidation.ISuccess<string> type
* console.log(result.data); // validated data accessible
* } else {
* // IValidation.IFailure type
* console.log(result.errors); // detailed error information accessible
* }
* ```
*
* @author Jeongho Nam - https://github.com/samchon
* @template T The type to validate
*/
export type IValidation<T = unknown> =
| IValidation.ISuccess<T>
| IValidation.IFailure;
export namespace IValidation {
/**
* Interface returned when type validation succeeds
*
* Returned when the input value perfectly conforms to the specified type T.
* Since success is true, TypeScript's type guard allows safe access to the
* validated data through the data property.
*
* @template T The validated type
*/
export interface ISuccess<T = unknown> {
/** Indicates validation success */
success: true;
/** The validated data of type T */
data: T;
}
/**
* Interface returned when type validation fails
*
* Returned when the input value does not conform to the expected type.
* Contains comprehensive error information designed to be easily understood
* by both humans and AI systems. Each error in the errors array provides
* precise details about validation failures, including the exact path to the
* problematic property, what type was expected, and what value was actually
* provided.
*
* This detailed error structure is specifically optimized for AI function
* calling validation feedback. When LLMs make type errors during function
* calling, these granular error reports enable the AI to understand exactly
* what went wrong and how to fix it, improving success rates in subsequent
* attempts.
*
* Example error scenarios:
*
* - Type mismatch: expected "string" but got number 5
* - Format violation: expected "string & Format<'uuid'>" but got
* "invalid-format"
* - Missing properties: expected "required property 'name'" but got undefined
* - Array type errors: expected "Array<string>" but got single string value
*
* The errors are used by ILlmFunction.validate() to provide structured
* feedback to AI agents, enabling them to correct their parameter generation
* and achieve improved function calling accuracy.
*/
export interface IFailure {
/** Indicates validation failure */
success: false;
/** The original input data that failed validation */
data: unknown;
/** Array of detailed validation errors */
errors: IError[];
}
/**
* Detailed information about a specific validation error
*
* Each error provides granular, actionable information about validation
* failures, designed to be immediately useful for both human developers and
* AI systems. The error structure follows a consistent format that enables
* precise identification and correction of type mismatches.
*
* This error format is particularly valuable for AI function calling
* scenarios, where LLMs need to understand exactly what went wrong to
* generate correct parameters. The combination of path, expected type name,
* actual value, and optional human-readable description provides the AI with
* comprehensive context to make accurate corrections, which is why
* ILlmFunction.validate() can achieve such high success rates in validation
* feedback loops.
*
* The value field can contain any type of data, including `undefined` when
* dealing with missing required properties or null/undefined validation
* scenarios. This allows for precise error reporting in cases where the AI
* agent omits required fields or provides null/undefined values
* inappropriately.
*
* Real-world examples from AI function calling:
*
* {
* path: "$input.member.age",
* expected: "number",
* value: "25" // AI provided string instead of number
* }
*
* {
* path: "$input.count",
* expected: "number & Type<'uint32'>",
* value: 20.75 // AI provided float instead of uint32
* }
*
* {
* path: "$input.categories",
* expected: "Array<string>",
* value: "technology" // AI provided string instead of array
* }
*
* {
* path: "$input.id",
* expected: "string & Format<'uuid'>",
* value: "invalid-uuid-format" // AI provided malformed UUID
* }
*
* {
* path: "$input.user.name",
* expected: "string",
* value: undefined // AI omitted required property
* }
*/
export interface IError {
/**
* The path to the property that failed validation
*
* Dot-notation path using $input prefix indicating the exact location of
* the validation failure within the input object structure. Examples
* include "$input.member.age", "$input.categories[0]",
* "$input.user.profile.email"
*/
path: string;
/**
* The expected type name or type expression
*
* Technical type specification that describes what type was expected at
* this path. This follows TypeScript-like syntax with embedded constraint
* information, such as "string", "number & Type<'uint32'>",
* "Array<string>", "string & Format<'uuid'> & MinLength<8>", etc.
*/
expected: string;
/**
* The actual value that caused the validation failure
*
* This field contains the actual value that was provided but failed
* validation. Note that this value can be `undefined` in cases where a
* required property is missing or when validating against undefined
* values.
*/
value: unknown;
/**
* Optional human-readable description of the validation error
*
* This field is rarely populated in standard typia validation and is
* primarily intended for specialized AI agent libraries or custom
* validation scenarios that require additional context beyond the technical
* type information. Most validation errors rely solely on the path,
* expected, and value fields for comprehensive error reporting.
*/
description?: string;
}
}
undefined
import { Equal } from "./typings/Equal";
import { NativeClass } from "./typings/NativeClass";
import { ValueOf } from "./typings/ValueOf";
/**
* Snake case type.
*
* `SnakeCase` type is a type that all keys of an object are converted to snake case.
*
* It also erase every method properties like {@link Resolved} type.
*
* @template T Target type to be snake cased
* @author Jeongho Nam - https://github.com/samchon
*/
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
/**
* Custom error class thrown when runtime assertion fails in `typia.assert<T>()` function.
*
* This error is thrown by the `typia.assert<T>()` function when the input value
* doesn't match the expected type.
*
* The error provides detailed information about the first assertion failure encountered,
* including the access path where the error occurred, the expected type, and the actual value.
*
* @template T - The expected type (generic for type safety)
* @author Jeongho Nam - https://github.com/samchon
* @example
* ```typescript
* interface IMember {
* name: string;
* age: number & ExclusiveMinimum<19>;
* }
*
* try {
* typia.assert<IMember>({ name: "John", age: 18 });
* } catch (error) {
* if (error instanceof TypeGuardError) {
* console.log(error.method); // "typia.assert"
* console.log(error.path); // "input.age"
* console.log(error.expected); // "number & ExclusiveMinimum<19>"
* console.log(error.value); // 18
* }
* }
* ```
*/
export class TypeGuardError<T = any> extends Error {
/**
* The name of the typia method that threw this error.
*
* @example "typia.assert"
*/
public readonly method: string;
/**
* The access path to the property where the assertion error occurred.
*
* Uses dot notation to indicate the path for nested object properties.
* May be `undefined` if the error occurred at the root level.
*
* @example
* - `"input.age"` - Error in the age property of the object
* - `"input.profile.email"` - Error in the email property of a nested object
* - `"input[0].name"` - Error in the name property of the first array element
* - `undefined` - Error occurred at the root level
*/
public readonly path: string | undefined;
/**
* String representation of the expected type at the error location.
*
* Represents TypeScript types as strings, including detailed type information
* for complex types.
*
* @example
* - `"string"` - Expected string type
* - `"number & ExclusiveMinimum<19>"` - Expected number greater than 19
* - `"undefined"` - Expected undefined (when superfluous property found in assertion)
* - `"{ name: string; age: number }"` - Expected object type
*/
public readonly expected: string;
/**
* The actual value that failed assertion.
*
* Stores the actual value at the error path as-is.
* Useful for debugging by comparing the expected type with the actual value.
*
* @example
* - `18` - Numeric value
* - `"invalid"` - String value
* - `{ name: "John", age: 18, sex: 1 }` - Object value
*/
public readonly value: unknown;
/**
* Phantom property for type safety purposes.
*
* This property is not actually used and exists only to maintain
* the generic type T in TypeScript's type system.
* Always has an `undefined` value at runtime.
*
* @internal
*/
protected readonly fake_expected_typed_value_?: T | undefined;
/**
* Creates a new TypeGuardError instance.
*
* @param props - Object containing the properties needed to create the error
*
* @example
* ```typescript
* const error = new TypeGuardError({
* method: "typia.assert",
* path: "input.age",
* expected: "number & ExclusiveMinimum<19>",
* value: 18
* });
* ```
*/
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;
}
}
export namespace TypeGuardError {
/**
* Interface for properties passed to the TypeGuardError constructor.
*
* @example
* ```typescript
* const props: TypeGuardError.IProps = {
* method: "typia.assertEquals",
* path: "input.sex",
* expected: "undefined",
* value: 1,
* message: "Custom error message" // optional
* };
* ```
*/
export interface IProps {
/**
* The name of the typia method that threw the error.
*
* @example "typia.assert", "typia.assertEquals"
*/
method: string;
/**
* The access path to the property where the assertion error occurred (optional).
*
* @example "input.age", "input.profile.email"
*/
path?: undefined | string;
/**
* String representation of the expected type at the error location.
*
* @example "string", "number & ExclusiveMinimum<19>"
*/
expected: string;
/**
* The actual value that failed assertion.
*/
value: unknown;
/**
* Custom error message (optional).
*
* If not provided, a default format message will be automatically generated.
*/
message?: undefined | string;
}
}
undefined
/**
* Union type representing the result of type validation
*
* This is the return type of {@link typia.validate} functions, returning
* {@link IValidation.ISuccess} on validation success and
* {@link IValidation.IFailure} on validation failure. When validation fails, it
* provides detailed, granular error information that precisely describes what
* went wrong, where it went wrong, and what was expected.
*
* This comprehensive error reporting makes `IValidation` particularly valuable
* for AI function calling scenarios, where Large Language Models (LLMs) need
* specific feedback to correct their parameter generation. The detailed error
* information is used by ILlmFunction.validate() to provide validation feedback
* to AI agents, enabling iterative correction and improvement of function
* calling accuracy.
*
* This type uses the Discriminated Union pattern, allowing type specification
* through the success property:
*
* ```typescript
* const result = typia.validate<string>(input);
* if (result.success) {
* // IValidation.ISuccess<string> type
* console.log(result.data); // validated data accessible
* } else {
* // IValidation.IFailure type
* console.log(result.errors); // detailed error information accessible
* }
* ```
*
* @author Jeongho Nam - https://github.com/samchon
* @template T The type to validate
*/
export type IValidation<T = unknown> =
| IValidation.ISuccess<T>
| IValidation.IFailure;
export namespace IValidation {
/**
* Interface returned when type validation succeeds
*
* Returned when the input value perfectly conforms to the specified type T.
* Since success is true, TypeScript's type guard allows safe access to the
* validated data through the data property.
*
* @template T The validated type
*/
export interface ISuccess<T = unknown> {
/** Indicates validation success */
success: true;
/** The validated data of type T */
data: T;
}
/**
* Interface returned when type validation fails
*
* Returned when the input value does not conform to the expected type.
* Contains comprehensive error information designed to be easily understood
* by both humans and AI systems. Each error in the errors array provides
* precise details about validation failures, including the exact path to the
* problematic property, what type was expected, and what value was actually
* provided.
*
* This detailed error structure is specifically optimized for AI function
* calling validation feedback. When LLMs make type errors during function
* calling, these granular error reports enable the AI to understand exactly
* what went wrong and how to fix it, improving success rates in subsequent
* attempts.
*
* Example error scenarios:
*
* - Type mismatch: expected "string" but got number 5
* - Format violation: expected "string & Format<'uuid'>" but got
* "invalid-format"
* - Missing properties: expected "required property 'name'" but got undefined
* - Array type errors: expected "Array<string>" but got single string value
*
* The errors are used by ILlmFunction.validate() to provide structured
* feedback to AI agents, enabling them to correct their parameter generation
* and achieve improved function calling accuracy.
*/
export interface IFailure {
/** Indicates validation failure */
success: false;
/** The original input data that failed validation */
data: unknown;
/** Array of detailed validation errors */
errors: IError[];
}
/**
* Detailed information about a specific validation error
*
* Each error provides granular, actionable information about validation
* failures, designed to be immediately useful for both human developers and
* AI systems. The error structure follows a consistent format that enables
* precise identification and correction of type mismatches.
*
* This error format is particularly valuable for AI function calling
* scenarios, where LLMs need to understand exactly what went wrong to
* generate correct parameters. The combination of path, expected type name,
* actual value, and optional human-readable description provides the AI with
* comprehensive context to make accurate corrections, which is why
* ILlmFunction.validate() can achieve such high success rates in validation
* feedback loops.
*
* The value field can contain any type of data, including `undefined` when
* dealing with missing required properties or null/undefined validation
* scenarios. This allows for precise error reporting in cases where the AI
* agent omits required fields or provides null/undefined values
* inappropriately.
*
* Real-world examples from AI function calling:
*
* {
* path: "$input.member.age",
* expected: "number",
* value: "25" // AI provided string instead of number
* }
*
* {
* path: "$input.count",
* expected: "number & Type<'uint32'>",
* value: 20.75 // AI provided float instead of uint32
* }
*
* {
* path: "$input.categories",
* expected: "Array<string>",
* value: "technology" // AI provided string instead of array
* }
*
* {
* path: "$input.id",
* expected: "string & Format<'uuid'>",
* value: "invalid-uuid-format" // AI provided malformed UUID
* }
*
* {
* path: "$input.user.name",
* expected: "string",
* value: undefined // AI omitted required property
* }
*/
export interface IError {
/**
* The path to the property that failed validation
*
* Dot-notation path using $input prefix indicating the exact location of
* the validation failure within the input object structure. Examples
* include "$input.member.age", "$input.categories[0]",
* "$input.user.profile.email"
*/
path: string;
/**
* The expected type name or type expression
*
* Technical type specification that describes what type was expected at
* this path. This follows TypeScript-like syntax with embedded constraint
* information, such as "string", "number & Type<'uint32'>",
* "Array<string>", "string & Format<'uuid'> & MinLength<8>", etc.
*/
expected: string;
/**
* The actual value that caused the validation failure
*
* This field contains the actual value that was provided but failed
* validation. Note that this value can be `undefined` in cases where a
* required property is missing or when validating against undefined
* values.
*/
value: unknown;
/**
* Optional human-readable description of the validation error
*
* This field is rarely populated in standard typia validation and is
* primarily intended for specialized AI agent libraries or custom
* validation scenarios that require additional context beyond the technical
* type information. Most validation errors rely solely on the path,
* expected, and value fields for comprehensive error reporting.
*/
description?: string;
}
}
undefined
import { Equal } from "./typings/Equal";
import { IsTuple } from "./typings/IsTuple";
import { NativeClass } from "./typings/NativeClass";
import { ValueOf } from "./typings/ValueOf";
/**
* Resolved type erased every methods.
*
* `Resolved` is a type of TMP (Type Meta Programming) type which converts
* its argument as a resolved type that erased every method properties.
*
* If the target argument is a built-in class which returns its origin primitive type
* through the `valueOf()` method like the `String` or `Number`, its return type would
* be the `string` or `number`. Otherwise, the built-in class does not have the
* `valueOf()` method, the return type would be same with the target argument.
*
* Otherwise, the target argument is a type of custom class, all of its custom methods
* would be erased and its prototype would be changed to the primitive `object`.
* Therefore, return type of the TMP type finally be the resolved object.
*
* Before | After
* ------------------------|----------------------------------------
* `Boolean` | `boolean`
* `Number` | `number`
* `BigInt` | `bigint`
* `String` | `string`
* `Class` | `interface`
* Native Class or Others | No change
*
* @template T Target argument type.
* @author Jeongho Nam - https://github.com/samchon
* @author Kyungsu Kang - https://github.com/kakasoo
*/
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.js";
import * as __typia_transform__httpQueryReadArray from "typia/lib/internal/_httpQueryReadArray.js";
import * as __typia_transform__httpQueryReadBoolean from "typia/lib/internal/_httpQueryReadBoolean.js";
import * as __typia_transform__httpQueryReadNumber from "typia/lib/internal/_httpQueryReadNumber.js";
import * as __typia_transform__httpQueryReadString from "typia/lib/internal/_httpQueryReadString.js";
(() => {
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
/**
* Custom error class thrown when runtime assertion fails in `typia.assert<T>()` function.
*
* This error is thrown by the `typia.assert<T>()` function when the input value
* doesn't match the expected type.
*
* The error provides detailed information about the first assertion failure encountered,
* including the access path where the error occurred, the expected type, and the actual value.
*
* @template T - The expected type (generic for type safety)
* @author Jeongho Nam - https://github.com/samchon
* @example
* ```typescript
* interface IMember {
* name: string;
* age: number & ExclusiveMinimum<19>;
* }
*
* try {
* typia.assert<IMember>({ name: "John", age: 18 });
* } catch (error) {
* if (error instanceof TypeGuardError) {
* console.log(error.method); // "typia.assert"
* console.log(error.path); // "input.age"
* console.log(error.expected); // "number & ExclusiveMinimum<19>"
* console.log(error.value); // 18
* }
* }
* ```
*/
export class TypeGuardError<T = any> extends Error {
/**
* The name of the typia method that threw this error.
*
* @example "typia.assert"
*/
public readonly method: string;
/**
* The access path to the property where the assertion error occurred.
*
* Uses dot notation to indicate the path for nested object properties.
* May be `undefined` if the error occurred at the root level.
*
* @example
* - `"input.age"` - Error in the age property of the object
* - `"input.profile.email"` - Error in the email property of a nested object
* - `"input[0].name"` - Error in the name property of the first array element
* - `undefined` - Error occurred at the root level
*/
public readonly path: string | undefined;
/**
* String representation of the expected type at the error location.
*
* Represents TypeScript types as strings, including detailed type information
* for complex types.
*
* @example
* - `"string"` - Expected string type
* - `"number & ExclusiveMinimum<19>"` - Expected number greater than 19
* - `"undefined"` - Expected undefined (when superfluous property found in assertion)
* - `"{ name: string; age: number }"` - Expected object type
*/
public readonly expected: string;
/**
* The actual value that failed assertion.
*
* Stores the actual value at the error path as-is.
* Useful for debugging by comparing the expected type with the actual value.
*
* @example
* - `18` - Numeric value
* - `"invalid"` - String value
* - `{ name: "John", age: 18, sex: 1 }` - Object value
*/
public readonly value: unknown;
/**
* Phantom property for type safety purposes.
*
* This property is not actually used and exists only to maintain
* the generic type T in TypeScript's type system.
* Always has an `undefined` value at runtime.
*
* @internal
*/
protected readonly fake_expected_typed_value_?: T | undefined;
/**
* Creates a new TypeGuardError instance.
*
* @param props - Object containing the properties needed to create the error
*
* @example
* ```typescript
* const error = new TypeGuardError({
* method: "typia.assert",
* path: "input.age",
* expected: "number & ExclusiveMinimum<19>",
* value: 18
* });
* ```
*/
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;
}
}
export namespace TypeGuardError {
/**
* Interface for properties passed to the TypeGuardError constructor.
*
* @example
* ```typescript
* const props: TypeGuardError.IProps = {
* method: "typia.assertEquals",
* path: "input.sex",
* expected: "undefined",
* value: 1,
* message: "Custom error message" // optional
* };
* ```
*/
export interface IProps {
/**
* The name of the typia method that threw the error.
*
* @example "typia.assert", "typia.assertEquals"
*/
method: string;
/**
* The access path to the property where the assertion error occurred (optional).
*
* @example "input.age", "input.profile.email"
*/
path?: undefined | string;
/**
* String representation of the expected type at the error location.
*
* @example "string", "number & ExclusiveMinimum<19>"
*/
expected: string;
/**
* The actual value that failed assertion.
*/
value: unknown;
/**
* Custom error message (optional).
*
* If not provided, a default format message will be automatically generated.
*/
message?: undefined | string;
}
}
undefined
/**
* Union type representing the result of type validation
*
* This is the return type of {@link typia.validate} functions, returning
* {@link IValidation.ISuccess} on validation success and
* {@link IValidation.IFailure} on validation failure. When validation fails, it
* provides detailed, granular error information that precisely describes what
* went wrong, where it went wrong, and what was expected.
*
* This comprehensive error reporting makes `IValidation` particularly valuable
* for AI function calling scenarios, where Large Language Models (LLMs) need
* specific feedback to correct their parameter generation. The detailed error
* information is used by ILlmFunction.validate() to provide validation feedback
* to AI agents, enabling iterative correction and improvement of function
* calling accuracy.
*
* This type uses the Discriminated Union pattern, allowing type specification
* through the success property:
*
* ```typescript
* const result = typia.validate<string>(input);
* if (result.success) {
* // IValidation.ISuccess<string> type
* console.log(result.data); // validated data accessible
* } else {
* // IValidation.IFailure type
* console.log(result.errors); // detailed error information accessible
* }
* ```
*
* @author Jeongho Nam - https://github.com/samchon
* @template T The type to validate
*/
export type IValidation<T = unknown> =
| IValidation.ISuccess<T>
| IValidation.IFailure;
export namespace IValidation {
/**
* Interface returned when type validation succeeds
*
* Returned when the input value perfectly conforms to the specified type T.
* Since success is true, TypeScript's type guard allows safe access to the
* validated data through the data property.
*
* @template T The validated type
*/
export interface ISuccess<T = unknown> {
/** Indicates validation success */
success: true;
/** The validated data of type T */
data: T;
}
/**
* Interface returned when type validation fails
*
* Returned when the input value does not conform to the expected type.
* Contains comprehensive error information designed to be easily understood
* by both humans and AI systems. Each error in the errors array provides
* precise details about validation failures, including the exact path to the
* problematic property, what type was expected, and what value was actually
* provided.
*
* This detailed error structure is specifically optimized for AI function
* calling validation feedback. When LLMs make type errors during function
* calling, these granular error reports enable the AI to understand exactly
* what went wrong and how to fix it, improving success rates in subsequent
* attempts.
*
* Example error scenarios:
*
* - Type mismatch: expected "string" but got number 5
* - Format violation: expected "string & Format<'uuid'>" but got
* "invalid-format"
* - Missing properties: expected "required property 'name'" but got undefined
* - Array type errors: expected "Array<string>" but got single string value
*
* The errors are used by ILlmFunction.validate() to provide structured
* feedback to AI agents, enabling them to correct their parameter generation
* and achieve improved function calling accuracy.
*/
export interface IFailure {
/** Indicates validation failure */
success: false;
/** The original input data that failed validation */
data: unknown;
/** Array of detailed validation errors */
errors: IError[];
}
/**
* Detailed information about a specific validation error
*
* Each error provides granular, actionable information about validation
* failures, designed to be immediately useful for both human developers and
* AI systems. The error structure follows a consistent format that enables
* precise identification and correction of type mismatches.
*
* This error format is particularly valuable for AI function calling
* scenarios, where LLMs need to understand exactly what went wrong to
* generate correct parameters. The combination of path, expected type name,
* actual value, and optional human-readable description provides the AI with
* comprehensive context to make accurate corrections, which is why
* ILlmFunction.validate() can achieve such high success rates in validation
* feedback loops.
*
* The value field can contain any type of data, including `undefined` when
* dealing with missing required properties or null/undefined validation
* scenarios. This allows for precise error reporting in cases where the AI
* agent omits required fields or provides null/undefined values
* inappropriately.
*
* Real-world examples from AI function calling:
*
* {
* path: "$input.member.age",
* expected: "number",
* value: "25" // AI provided string instead of number
* }
*
* {
* path: "$input.count",
* expected: "number & Type<'uint32'>",
* value: 20.75 // AI provided float instead of uint32
* }
*
* {
* path: "$input.categories",
* expected: "Array<string>",
* value: "technology" // AI provided string instead of array
* }
*
* {
* path: "$input.id",
* expected: "string & Format<'uuid'>",
* value: "invalid-uuid-format" // AI provided malformed UUID
* }
*
* {
* path: "$input.user.name",
* expected: "string",
* value: undefined // AI omitted required property
* }
*/
export interface IError {
/**
* The path to the property that failed validation
*
* Dot-notation path using $input prefix indicating the exact location of
* the validation failure within the input object structure. Examples
* include "$input.member.age", "$input.categories[0]",
* "$input.user.profile.email"
*/
path: string;
/**
* The expected type name or type expression
*
* Technical type specification that describes what type was expected at
* this path. This follows TypeScript-like syntax with embedded constraint
* information, such as "string", "number & Type<'uint32'>",
* "Array<string>", "string & Format<'uuid'> & MinLength<8>", etc.
*/
expected: string;
/**
* The actual value that caused the validation failure
*
* This field contains the actual value that was provided but failed
* validation. Note that this value can be `undefined` in cases where a
* required property is missing or when validating against undefined
* values.
*/
value: unknown;
/**
* Optional human-readable description of the validation error
*
* This field is rarely populated in standard typia validation and is
* primarily intended for specialized AI agent libraries or custom
* validation scenarios that require additional context beyond the technical
* type information. Most validation errors rely solely on the path,
* expected, and value fields for comprehensive error reporting.
*/
description?: string;
}
}
undefined
import { Equal } from "./typings/Equal";
import { IsTuple } from "./typings/IsTuple";
import { NativeClass } from "./typings/NativeClass";
import { ValueOf } from "./typings/ValueOf";
/**
* Resolved type erased every methods.
*
* `Resolved` is a type of TMP (Type Meta Programming) type which converts
* its argument as a resolved type that erased every method properties.
*
* If the target argument is a built-in class which returns its origin primitive type
* through the `valueOf()` method like the `String` or `Number`, its return type would
* be the `string` or `number`. Otherwise, the built-in class does not have the
* `valueOf()` method, the return type would be same with the target argument.
*
* Otherwise, the target argument is a type of custom class, all of its custom methods
* would be erased and its prototype would be changed to the primitive `object`.
* Therefore, return type of the TMP type finally be the resolved object.
*
* Before | After
* ------------------------|----------------------------------------
* `Boolean` | `boolean`
* `Number` | `number`
* `BigInt` | `bigint`
* `String` | `string`
* `Class` | `interface`
* Native Class or Others | No change
*
* @template T Target argument type.
* @author Jeongho Nam - https://github.com/samchon
* @author Kyungsu Kang - https://github.com/kakasoo
*/
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.js";
import * as __typia_transform__httpHeaderReadNumber from "typia/lib/internal/_httpHeaderReadNumber.js";
(() => {
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
/**
* Custom error class thrown when runtime assertion fails in `typia.assert<T>()` function.
*
* This error is thrown by the `typia.assert<T>()` function when the input value
* doesn't match the expected type.
*
* The error provides detailed information about the first assertion failure encountered,
* including the access path where the error occurred, the expected type, and the actual value.
*
* @template T - The expected type (generic for type safety)
* @author Jeongho Nam - https://github.com/samchon
* @example
* ```typescript
* interface IMember {
* name: string;
* age: number & ExclusiveMinimum<19>;
* }
*
* try {
* typia.assert<IMember>({ name: "John", age: 18 });
* } catch (error) {
* if (error instanceof TypeGuardError) {
* console.log(error.method); // "typia.assert"
* console.log(error.path); // "input.age"
* console.log(error.expected); // "number & ExclusiveMinimum<19>"
* console.log(error.value); // 18
* }
* }
* ```
*/
export class TypeGuardError<T = any> extends Error {
/**
* The name of the typia method that threw this error.
*
* @example "typia.assert"
*/
public readonly method: string;
/**
* The access path to the property where the assertion error occurred.
*
* Uses dot notation to indicate the path for nested object properties.
* May be `undefined` if the error occurred at the root level.
*
* @example
* - `"input.age"` - Error in the age property of the object
* - `"input.profile.email"` - Error in the email property of a nested object
* - `"input[0].name"` - Error in the name property of the first array element
* - `undefined` - Error occurred at the root level
*/
public readonly path: string | undefined;
/**
* String representation of the expected type at the error location.
*
* Represents TypeScript types as strings, including detailed type information
* for complex types.
*
* @example
* - `"string"` - Expected string type
* - `"number & ExclusiveMinimum<19>"` - Expected number greater than 19
* - `"undefined"` - Expected undefined (when superfluous property found in assertion)
* - `"{ name: string; age: number }"` - Expected object type
*/
public readonly expected: string;
/**
* The actual value that failed assertion.
*
* Stores the actual value at the error path as-is.
* Useful for debugging by comparing the expected type with the actual value.
*
* @example
* - `18` - Numeric value
* - `"invalid"` - String value
* - `{ name: "John", age: 18, sex: 1 }` - Object value
*/
public readonly value: unknown;
/**
* Phantom property for type safety purposes.
*
* This property is not actually used and exists only to maintain
* the generic type T in TypeScript's type system.
* Always has an `undefined` value at runtime.
*
* @internal
*/
protected readonly fake_expected_typed_value_?: T | undefined;
/**
* Creates a new TypeGuardError instance.
*
* @param props - Object containing the properties needed to create the error
*
* @example
* ```typescript
* const error = new TypeGuardError({
* method: "typia.assert",
* path: "input.age",
* expected: "number & ExclusiveMinimum<19>",
* value: 18
* });
* ```
*/
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;
}
}
export namespace TypeGuardError {
/**
* Interface for properties passed to the TypeGuardError constructor.
*
* @example
* ```typescript
* const props: TypeGuardError.IProps = {
* method: "typia.assertEquals",
* path: "input.sex",
* expected: "undefined",
* value: 1,
* message: "Custom error message" // optional
* };
* ```
*/
export interface IProps {
/**
* The name of the typia method that threw the error.
*
* @example "typia.assert", "typia.assertEquals"
*/
method: string;
/**
* The access path to the property where the assertion error occurred (optional).
*
* @example "input.age", "input.profile.email"
*/
path?: undefined | string;
/**
* String representation of the expected type at the error location.
*
* @example "string", "number & ExclusiveMinimum<19>"
*/
expected: string;
/**
* The actual value that failed assertion.
*/
value: unknown;
/**
* Custom error message (optional).
*
* If not provided, a default format message will be automatically generated.
*/
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.js";
import * as __typia_transform__httpParameterReadNumber from "typia/lib/internal/_httpParameterReadNumber.js";
import * as __typia_transform__httpParameterReadString from "typia/lib/internal/_httpParameterReadString.js";
import * as __typia_transform__isFormatUuid from "typia/lib/internal/_isFormatUuid.js";
import * as __typia_transform__isTypeUint32 from "typia/lib/internal/_isTypeUint32.js";
(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);
};