https://github.com/seangenabe/non-null
TypeScript helper. Assert if a value is neither null nor undefined.
https://github.com/seangenabe/non-null
assert typescript typescript-helper
Last synced: about 2 months ago
JSON representation
TypeScript helper. Assert if a value is neither null nor undefined.
- Host: GitHub
- URL: https://github.com/seangenabe/non-null
- Owner: seangenabe
- License: mit
- Created: 2018-01-15T09:54:55.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-07-11T03:45:40.000Z (about 7 years ago)
- Last Synced: 2025-07-04T02:47:28.929Z (3 months ago)
- Topics: assert, typescript, typescript-helper
- Language: TypeScript
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
README
## non-null
TypeScript helper. Assert if a value is neither null nor undefined.
## Declaration
```typescript
export default function nonNull(arg?: T | null, message?: string): T
export { nonNull as nn }
```## Usage
```typescript
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](https://github.com/unassert-js/unassert).