1.4.0 • Published 10 months ago

assert-never v1.4.0

Weekly downloads
559,533
License
MIT
Repository
github
Last release
10 months 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-1172t-graphqltest-db-servicespot-liangjihuaviteshot@previewjs/serializable-values@previewjs/testing@previewjs/ts-helpers@previewjs/type-analyzer@previewjs/vfsjest-compact-reporterkekalkira-clientkira-core-firebasekira-server-firebase@ui5-language-assistant/xml-views-completion@ui5-language-assistant/language-server@zalastax/nolb-assealisselisss-lab3agikit-coreagikit-pic-editor@agikit/core@agikit/react-editors@af_cargo/spot@ef-carbon/react-native-dom@ef-carbon/react-native-style@ef-carbon/chat-bot-generator-conversation@ef-carbon/conversation@ef-carbon/dom@ef-carbon/input@codemod-tools/babel-scope@airtasker/spot@alch/alchemy-web3tsprotobuf-codec@cardstack/hub@brydget/restifyts-shift@mservicestech/spot@previewjs/core@previewjs/e2e-test-runner@previewjs/app-foundations@runtyping/test-type-writers@real_ate/fake-embroider-compat@real_ate/fake-embroider-macros@real_ate/fake-embroider-vite@real_ate/fake-embroider-webpack@poker-apprentice/hand-history-analyzer@poker-apprentice/hand-history-parser@paima/mw-core@paima/providers@sdeverywhere/check-core@sdeverywhere/check-ui-shell@sdeverywhere/parse@sdeverywhere/plugin-check@rollingversions/canarymfsqlcheckerreact-native-remote-websb-apirelease-planprettier-plugin-slicepumpdotfunproxayrethinkdb-watchreact-screenshot-testreact-screenshot-test-tt-forkreact-visual-regression-testslice2mdslice2tscalderacj-tag-checkerdmenu-jsonember-webpack-hot-reloadember-animatedetts@cubejs-backend/api-gateway@dmgt/google-ad-manager-api@fluentui-react-native/theme-tokens@fluentui-react-native/experimental-activity-indicator@fluentui-react-native/experimental-shimmer@fluentui-react-native/default-theme@fluentui-react-native/apple-theme@dinert/component@firestore-emulator/server@johngw/google-ad-manager-api@johngw/stream@johngw/stream-common@johngw/stream-test@fast-rn/core@databases/pg@databases/pg-migrations@databases/pg-schema-print-types@databases/bigquery@databases/migrations-base@databases/mock-db@databases/mysql-schema-print-types@medflyt/mfsqlchecker
1.4.0

10 months ago

1.3.0

1 year ago

1.2.1

5 years ago

1.2.0

6 years ago

1.1.0

8 years ago

1.0.0

9 years ago