github samchon/typia v5.5.2

latest releases: v6.12.0, v6.11.4, v6.11.3...
8 months ago

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

New Contributors

Full Changelog: v5.4.14...v5.5.2

Don't miss a new typia release

NewReleases is sending notifications on new releases.