pax_global_header00006660000000000000000000000064136566732350014532gustar00rootroot0000000000000052 comment=a5197695021f865f8165bbe3b1a6803d20bb0fb6 assert-never-1.2.1/000077500000000000000000000000001365667323500141515ustar00rootroot00000000000000assert-never-1.2.1/.gitignore000066400000000000000000000001501365667323500161350ustar00rootroot00000000000000# IntelliJ IDEA .idea *.iml # NPM node_modules npm-*.log # OS X .DS_Store # build index.d.ts index.jsassert-never-1.2.1/README.md000066400000000000000000000016021365667323500154270ustar00rootroot00000000000000# Assert Never [![npm version][npm-image]][npm-url] Helper function for [exhaustive checks][exhaustive-checks] of discriminated unions in TypeScript. ## Installation ``` npm install --save assert-never ``` ## Usage ```ts 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); } ``` [npm-image]: https://badge.fury.io/js/assert-never.svg [npm-url]: https://badge.fury.io/js/assert-never [exhaustive-checks]: https://basarat.gitbooks.io/typescript/docs/types/discriminated-unions.html#exhaustive-checks assert-never-1.2.1/index.ts000066400000000000000000000016121365667323500156300ustar00rootroot00000000000000/** * Helper function for exhaustive checks of discriminated unions. * https://basarat.gitbooks.io/typescript/docs/types/discriminated-unions.html * * @example * * 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); * } */ export function assertNever(value: never, noThrow?: boolean): never { if (noThrow) { return value } throw new Error( `Unhandled discriminated union member: ${JSON.stringify(value)}`, ); } export default assertNever; assert-never-1.2.1/package.json000066400000000000000000000011251365667323500164360ustar00rootroot00000000000000{ "name": "assert-never", "version": "1.2.1", "description": "Helper function for exhaustive checks of discriminated unions in TypeScript", "main": "index.js", "typings": "index.d.ts", "files": [ "index.js", "index.ts", "index.d.ts" ], "scripts": { "build": "tsc", "prepublish": "npm run build" }, "keywords": [ "typescript", "discriminated unions", "assert", "never" ], "repository": "aikoven/assert-never", "author": "Daniel Lytkin ", "license": "MIT", "devDependencies": { "typescript": "^2.2.1" } } assert-never-1.2.1/tsconfig.json000066400000000000000000000004141365667323500166570ustar00rootroot00000000000000{ "compilerOptions": { "target": "es5", "module": "commonjs", "declaration": true, "declarationDir": ".", "outDir": ".", "noImplicitReturns": true, "noImplicitAny": true, "strictNullChecks": true }, "files": [ "index.ts" ] }assert-never-1.2.1/yarn.lock000066400000000000000000000003601365667323500157730ustar00rootroot00000000000000# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. # yarn lockfile v1 typescript@^2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.2.1.tgz#4862b662b988a4c8ff691cc7969622d24db76ae9"