0.0.6 • Published 3 years ago

ts-runtime-validator v0.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

ts-runtime-validator

A Typescript transformer to generate runtime validation functions from type definitions.

type Foo = {
  bar: string;
  baz: number | null;
};

const invalid = {
  bar: 123,
};

validateType<Foo>(invalid); // Not of type 'Foo', throws an exception

const valid: any = {
  bar: 'valid',
  baz: 1,
};

validateType<Foo>(valid); // Type guard, asserts that valid is Foo
console.log(valid.bar); // 'valid'

try {
  const input: any = { bar: 'a' };
  validateType<Foo>(input);
  console.log(input.baz);
} catch (e) {
  // Required field is missing: baz
}
0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.4-0

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago