Fatima Logofatima

typia

"Super-fast/easy runtime validators and serializers via transformation"

Dependencies

npm install typia

Importing the validator

Generate your types

If you generate your types before writing validation, they will be available to help you define the constraint.

Do not write the schema in other file

The current validator transforms the config file, so the schema must be inside it.

Do not pass the function without executing it

Do not pass the function to the validator without executing it, typia will not read it correctly.

env.config.ts
❌ validators.typia(typia.validate<Schema>);
 
✅ validators.typia((env) => typia.validate<Schema>(env));
env.config.ts
import { config, validators } from "fatima";
import typia, { tags } from "typia";
import { EnvRecord } from "env";
 
type Constraint = EnvType<{
  NODE_ENV: string & tags.Format<"email">;
  TZ: string;
}>;
 
export default config({
  // WARNING: Do not pass the validate function without executing it here.
  validate: validators.typia((env) => typia.validate<Schema>(env)),
});

Validate

To validate, just run the validate command:

npm fatima validate

On this page