literalTypeGuard
Builds a guard accepting exactly the listed values.
Import:
import { literalTypeGuard } from '@mnaoumov/typescript-lib/type-guards';Signature:
function literalTypeGuard(literals: Readonly<Record<string, true>> | readonly Literal[]): TypeGuard<Literal>Parameters:
| Parameter | Type | Description |
|---|---|---|
literals |
Readonly<Record<string, true>> | readonly Literal[] | The accepted values, as a list or as the keys of a record. |
Returns: TypeGuard<Literal> — The guard.
Links to this page: