UNPKG

typia

Version:

Superfast runtime validators with only one line

42 lines (41 loc) 1.49 kB
//#region src/TypeGuardError.ts /** * Error thrown when type assertion fails. * * Thrown by {@link assert}, {@link assertGuard}, and other assert-family * functions when input doesn't match expected type `T`. Contains detailed * information about the first assertion failure: * * - `method`: Which typia function threw (e.g., `"typia.assert"`) * - `path`: Property path where error occurred (e.g., `"input.user.age"`) * - `expected`: Expected type string (e.g., `"number & ExclusiveMinimum<19>"`) * - `value`: Actual value that failed validation * * @template T Expected type (for type safety) */ var TypeGuardError = class extends Error { /** * Creates a new TypeGuardError instance. * * @param props Error properties */ constructor(props) { super(props.message || `Error on ${props.method}(): invalid type${props.path ? ` on ${props.path}` : ""}, expect to be ${props.expected}`); const proto = new.target.prototype; if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto); else this.__proto__ = proto; this.name = "TypeGuardError"; this.method = props.method; this.path = props.path; this.expected = props.expected; this.value = props.value; if (props.description || props.value === void 0) this.description = props.description ?? [ "The value at this path is `undefined`.", "", `Please fill the \`${props.expected}\` typed value next time.` ].join("\n"); } }; //#endregion export { TypeGuardError }; //# sourceMappingURL=TypeGuardError.mjs.map