New module functional
for entire function level validation.
export namespace functional {
export function assertFunction<T extends Function>(func: T): T;
export function isFunction<T extends (...args: any[]) => any>(
func: T,
): T extends (...args: infer Arguments) => infer Output
? Output extends Promise<infer R>
? (...args: Arguments) => Promise<R | null>
: (...args: Arguments) => Output | null
: never;
export function validateFunction<T extends (...args: any[]) => any>(
func: T,
): T extends (...args: infer Arguments) => infer Output
? Output extends Promise<infer R>
? (...args: Arguments) => Promise<IValidation<R>>
: (...args: Arguments) => IValidation<Output>
: never;
}
Also, when using assert
functions, you can customize the error class to throw.
import typia from "typia";
class MyCustomError extends Error {
public constructor(props: typia.TypeGuard.IProps);
}
typia.assert<number>("not-a-number", (props) => MyCustomError(props));
Additionally, checked that no problem on the new TypeScript v5.4 update.
What's Changed
- Prepare #954 - custom type assertion error. by @samchon in #985
- Documentation of #954 by @samchon in #987
- docs: fix typo by @KhooHaoYit in #988
- Close #954 -
typia.functional.assertFunction()
. by @samchon in #989 - Complement #954 -
isFunction()
andvalidateFunction()
. by @samchon in #992 - Publish v5.5 and documentation by @samchon in #993
- Fix
typia.functional
module for async or implicit return type case. by @samchon in #994 - Update typescript requirement from ^5.3.3 to ^5.4.2 by @dependabot in #995
- Fix mis-generated type bug of async
functional
module when generation mode by @samchon in #997
New Contributors
- @KhooHaoYit made their first contribution in #988
Full Changelog: v5.4.14...v5.5.2