1.2.1 • Published 4 years ago

assert-never v1.2.1

Weekly downloads
559,533
License
MIT
Repository
github
Last release
4 years ago

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);
}
with@af_selim/spot@olivervorasai/sliderasterjs@everything-registry/sub-chunk-1172ember-animatedember-webpack-hot-reloadetts@object-studio/react-native-web@poker-apprentice/hand-history-analyzer@poker-apprentice/hand-history-parser@sdeverywhere/check-core@sdeverywhere/check-ui-shell@sdeverywhere/parse@sdeverywhere/plugin-check@previewjs/testing@previewjs/ts-helpers@previewjs/type-analyzer@previewjs/vfs@previewjs/app-foundations@previewjs/core@previewjs/e2e-test-runner@previewjs/serializable-values@lukeapage/babel-scopeviteshot@notmeagain/proxay@ef-carbon/input@ef-carbon/react-native-dom@ef-carbon/react-native-style@ef-carbon/chat-bot-generator-conversation@ef-carbon/conversation@ef-carbon/domcalderatest-db-service@enepti/alchemy-web3@embroider/vite@embroider/webpack@embroider/compat@embroider/coremfsqlchecker@runtyping/test-type-writersdmenu-json@real_ate/fake-embroider-compat@real_ate/fake-embroider-macros@real_ate/fake-embroider-vite@real_ate/fake-embroider-webpack@paima/mw-core@paima/providers@firestore-emulator/servertsprotobuf-codects-shift@rollingversions/canary@embroider/macrosreact-native-remote-webreact-visual-regression-testreact-screenshot-testreact-screenshot-test-tt-forkagikit-coreagikit-pic-editor@brydget/restify@codemod-tools/babel-scopekekalslice2mdslice2tsrelease-planrethinkdb-watch@dinert/component@dinert/echarts@databases/migrations-base@databases/mock-db@databases/mysql-schema-print-types@databases/pg@databases/pg-migrations@databases/pg-schema-print-types@databases/bigqueryt-graphql@cardstack/hubkira-clientkira-core-firebasekira-server-firebasealisselisss-lab3jest-compact-reportersb-api@fast-rn/corecj-tag-checker@fluentui-react-native/theme-tokens@fluentui-react-native/default-theme@fluentui-react-native/experimental-shimmer@fluentui-react-native/experimental-activity-indicator@fluentui-react-native/apple-theme@johngw/stream@johngw/stream-common@johngw/stream-test@johngw/google-ad-manager-api@ui5-language-assistant/language-serverprettier-plugin-sliceproxay@alch/alchemy-web3@ui5-language-assistant/xml-views-completion@airtasker/spot
1.2.1

4 years ago

1.2.0

5 years ago

1.1.0

6 years ago

1.0.0

7 years ago