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

2.0.1 • Public • Published

non-null

TypeScript helper. Assert if a value is neither null nor undefined.

Declaration

export default function nonNull<T = any>(arg?: T | null, message?: string): T
export { nonNull as nn }

Usage

import nonNull from 'non-null'
 
nonNull(1) // = 1
nonNull(null) // throws an error
nonNull(undefined) // throws an error

Assert if a value is neither null nor undefined using the assert module. Returns the value.

Note that the type return value is coerced to be non-null.

Tip

To remove assert calls, use a tool such as unassert.

Readme

Keywords

Package Sidebar

Install

npm i non-null

Weekly Downloads

54

Version

2.0.1

License

MIT

Unpacked Size

4.18 kB

Total Files

10

Last publish

Collaborators

  • seangenabe