GrauKatze 05f70669c9 Сконфигурирована и подготовлена база для проекта | il y a 2 ans | |
---|---|---|
.. | ||
README.md | il y a 2 ans | |
index.d.ts | il y a 2 ans | |
index.js | il y a 2 ans | |
index.ts | il y a 2 ans | |
package.json | il y a 2 ans |
Helper function for exhaustive checks of discriminated unions in TypeScript.
npm install --save assert-never
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);
}