utility-types is a comprehensive collection of TypeScript utility types designed to complement and extend TypeScript's built-in mapped types and aliases. Currently stable at v3.11.0, the library maintains an active release schedule, frequently introducing new type utilities and refining existing ones to keep pace with TypeScript's evolution and community needs. It differentiates itself by offering a broad range of idiomatic types, including those compatible with Flow's utility types to aid migration efforts, all without introducing any runtime cost. The package prides itself on being secure and minimal, having no third-party dependencies and ensuring type correctness through rigorous testing with `dts-jest`. Its primary goal is to provide developers with a robust, zero-cost 'lodash' for static types, eliminating the need to re-implement common type patterns across projects.
npm install utility-typesVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use several key utility types from the `utility-types` library, including `DeepReadonly` for deep immutability, `Optional` for making specific properties optional, and `Falsy`, `Primitive`, and `Nullish` for working with common JavaScript value classifications at the type level.
Ensure your project's TypeScript version meets the requirements of the `utility-types` major version you are using. Upgrade TypeScript if necessary.
Replace all instances of `Falsey` with `Falsy` in your codebase.
Consider upgrading your TypeScript version to `v3.6` or newer to benefit from resolved `Omit` issues and more stable type inference. If stuck on TS v3.5, be aware of potential `Omit` behavior differences.
Review code that uses `PickByValue`, `OmitByValue`, `PickByValueExact`, or `OmitByValueExact` after upgrading to v3.10.0, especially if it relies on `undefined` being part of the resulting key types. Adjust type assertions or logic as needed.
Thoroughly test your codebase after upgrading `utility-types` to a new minor version. Consult the release notes for specific changes that might affect your project.
Add an import statement for the specific type: `import { Primitive } from 'utility-types';`Ensure the type you're using (e.g., `Falsy`, `Nullish`) accurately reflects the allowed values. If only `null` or `undefined` are desired, use `Nullish`. For other falsy values, understand the full scope of `Falsy` or define a more precise custom type.
If modification is required, create a mutable copy of the object before applying `DeepReadonly` or work with the original mutable object. If only top-level immutability is needed, use TypeScript's built-in `Readonly<T>`.
No dependency data recorded yet.