nullables
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i nullables

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

7.94 kB

Total Files

7

Last publish

Collaborators

  • aabbccsmith