typescript-union
raw JSON → 0.2.0 verified Mon Apr 27 auth: no javascript deprecated
A utility library providing generic types for manipulating TypeScript unions at the type level. Version 0.2.0 is current; the package is experimental and sees infrequent updates. Key differentiators: offers type transformations such as filtering and mapping union members without runtime code. Alternatives like type-fest or utility-types provide broader type utilities but may lack union-specific operations.
Common errors
error Cannot find module 'typescript-union' or its corresponding type declarations. ↓
cause Package not installed or missing type definitions.
fix
Install: npm install typescript-union --save-dev
error 'Filter' cannot be used as a value because it is a type. ↓
cause Runtime usage of a type-only export.
fix
Remove from runtime code or use import type.
Warnings
deprecated Package is abandoned; no updates since 2020. ↓
fix Consider alternatives like type-fest or ts-essentials.
gotcha All exports are types only; importing at runtime will cause errors. ↓
fix Use import type syntax: import type { Filter } from 'typescript-union'.
breaking Removal of deprecated type aliases in version 0.2.0. ↓
fix Replace deprecated aliases with the new names per changelog.
Install
npm install typescript-union yarn add typescript-union pnpm add typescript-union Imports
- Filter
import { Filter } from 'typescript-union' - Split wrong
const { Split } = require('typescript-union')correctimport { Split } from 'typescript-union' - UnionToIntersection
import { UnionToIntersection } from 'typescript-union'
Quickstart
import { Filter, UnionToIntersection } from 'typescript-union';
type Mixed = string | number | boolean;
type OnlyStrings = Filter<Mixed, string>; // string
type Funcs = ((x: string) => void) | ((x: number) => void);
type Intersected = UnionToIntersection<Funcs>; // (x: string & number) => void