npm.io
1.0.2 • Published 5 years ago

nullables

Licence
MIT
Version
1.0.2
Deps
2
Size
8 kB
Vulns
0
Weekly
0
Stars
1

nullables

A way to specify nullable types in TypeScript whilst still getting the correct data at runtime.

Usage

import { Property, NullableString, RemapProperties } from 'nullables';

class Person {
  @Property
  email!: string;

  @Property
  age!: number;

  @Property
  first_name!: NullableString;
}

// Remap properties to now have correct types at compile/dev time
// but maintain String at runtime (with the knowledge of it being nullable)
const person = new Person() as RemapProperties<Person>;

person.age; // => number
person.first_name; // => string | null
person.email; // => string