npm.io
0.0.1 • Published 4 years ago

ts-void

Licence
MIT
Version
0.0.1
Deps
0
Size
4 kB
Vulns
0
Weekly
0
Stars
4


TS-VOIDɸ

“The eternal void is filled with infinite possibilities” ~ Laozi

Typescript Void npm

Void

How do you check if this variable contains a value?

let value: Value;

You may initialize it with undefined or null, but what if Value is a generic you don't control, and it can be one of these values?

import { Void } from "ts-void";

You may use Void as a new primitive value.

let value: Value | Void;

then you can check if the variable is Void.

if (value !== Void) {
  // Now the value is only of type "Value".
}

You may also use the utility type.

import { type NonVoid } from "ts-void";

And extract the original type from the union.

type Extracted = NonVoid<T | Void>; // equals to T.

Keywords