assert-never
Helper function for exhaustive checks of discriminated unions in TypeScript
Last updated 7 years ago by aikoven .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install assert-never 
SYNC missed versions from official npm registry.

Assert Never npm version

Helper function for exhaustive checks of discriminated unions in TypeScript.

Installation

npm install --save assert-never

Usage

import {assertNever} from "assert-never";

type A = {type: 'a'};
type B = {type: 'b'};
type Union = A | B;

function doSomething(arg: Union) {
  if (arg.type === 'a') {
    return something;
  }

  if (arg.type === 'b') {
    return somethingElse;
  }

  // TS will error if there are other types in the union
  // Will throw an Error when called at runtime. Use `assertNever(arg, true)`
  // instead to fail silently.
  return assertNever(arg);
}

Current Tags

  • 1.3.0                                ...           latest (2 years ago)

5 Versions

  • 1.3.0                                ...           2 years ago
  • 1.2.1                                ...           6 years ago
  • 1.2.0                                ...           7 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.0                                ...           9 years ago
Maintainers (1)
Downloads
Today 0
This Week 12
This Month 22
Last Day 5
Last Week 18
Last Month 136
Dependencies (0)
None
Dev Dependencies (1)
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |