arktypea
arktype10mo ago
Kuba

Throw on failed validation

Does Arktype throws on failed validation?
I saw that there's a onFail in docs, so I've configured it and imported it before artype itself in place of use, but still no error was thrown.
// arktype-conf.ts
import { configure } from "arktype";

const config = configure({
  onFail: (errors) => errors.throw(),
});

declare global {
  interface ArkEnv {
    onFail: typeof config.onFail;
  }
}

// example.ts
import "./arktype-conf";
import { type } from "arktype";

const User = type({
  name: "string",
  age: "number",
});

// const user = User({ name: "John", age: 30 });
const user = User({ name: "John" });
// exits gracefully, but user contains an error
// no error throw happens


I expected this config to change the behavior of arktype to throw instead. Is it possible or is it by design? Not that I need it, was just curious if this is possible or I did/understood something wrong.
Optimized runtime validation for TypeScript syntax
Was this page helpful?