1.4.0 • Published 6 months ago

assert-never v1.4.0

Weekly downloads
559,533
License
MIT
Repository
github
Last release
6 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@dmgt/google-ad-manager-api@dinert/component@previewjs/serializable-values@previewjs/testing@previewjs/ts-helpers@previewjs/type-analyzer@previewjs/vfsjest-compact-reporterkekalkira-clientkira-core-firebasekira-server-firebasetsprotobuf-codec@af_cargo/spot@alch/alchemy-web3@airtasker/spot@agikit/core@agikit/react-editors@cardstack/hub@brydget/restify@codemod-tools/babel-scope@databases/bigquery@databases/migrations-base@databases/mock-db@databases/pg-migrations@databases/pg-schema-print-types@databases/mysql-schema-print-types@databases/pgts-shift@fast-rn/core@fluentui-react-native/theme-tokens@fluentui-react-native/apple-theme@fluentui-react-native/experimental-shimmer@fluentui-react-native/default-theme@fluentui-react-native/experimental-activity-indicator@firestore-emulator/server@embroider/vite@embroider/webpack@embroider/compat@embroider/core@embroider/macros@gitbook/react-contentkit@lukeapage/babel-scope@mservicestech/spot@enepti/alchemy-web3@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@medflyt/test-db-service@johngw/stream@johngw/stream-common@johngw/stream-test@johngw/google-ad-manager-api@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@notmeagain/proxay@object-studio/react-native-web@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-testslice2mdslice2ts@ui5-language-assistant/xml-views-completion@ui5-language-assistant/language-server@zalastax/nolb-asse
1.4.0

6 months ago

1.3.0

11 months ago

1.2.1

5 years ago

1.2.0

6 years ago

1.1.0

7 years ago

1.0.0

8 years ago