ts-extras
Version:
Essential utilities for TypeScript projects
21 lines (15 loc) • 524 B
TypeScript
/**
Assert that the given value is present (non-nullable), meaning it is neither `null` nor `undefined`.
If the value is not present (`undefined` or `null`), a helpful `TypeError` will be thrown.
@example
```
import {assertPresent} from 'ts-extras';
const unicorn = 'unicorn';
assertPresent(unicorn);
const notUnicorn = null;
assertPresent(notUnicorn);
//=> TypeError: Expected a present value, got `null`
```
@category Type guard
*/
export declare function assertPresent<T>(value: T): asserts value is NonNullable<T>;