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