{"id":12331,"library":"utility-types","title":"TypeScript Utility Types Collection","description":"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.","status":"active","version":"3.11.0","language":"javascript","source_language":"en","source_url":"https://github.com/piotrwitek/utility-types","tags":["javascript","typescript","utility","types","static-typing","mapped-types","flow","flow-typed"],"install":[{"cmd":"npm install utility-types","lang":"bash","label":"npm"},{"cmd":"yarn add utility-types","lang":"bash","label":"yarn"},{"cmd":"pnpm add utility-types","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This library provides type definitions only; there is no runtime artifact to `require`.","wrong":"const DeepReadonly = require('utility-types');","symbol":"DeepReadonly","correct":"import { DeepReadonly } from 'utility-types';"},{"note":"All utility types are named exports. There is no default export.","wrong":"import Optional from 'utility-types';","symbol":"Optional","correct":"import { Optional } from 'utility-types';"},{"note":"`Falsey` was deprecated in v3.9.0 in favor of `Falsy`. New code should use `Falsy`.","wrong":"import { Falsey } from 'utility-types';","symbol":"Falsy","correct":"import { Falsy } from 'utility-types';"},{"symbol":"Primitive","correct":"import { Primitive } from 'utility-types';"}],"quickstart":{"code":"import { DeepReadonly, Optional, Falsy, Primitive, Nullish } from 'utility-types';\n\ninterface User {\n  id: number;\n  name: string;\n  email?: string;\n  settings: {\n    theme: 'dark' | 'light';\n    notificationsEnabled: boolean;\n  };\n}\n\n// DeepReadonly: Makes all properties, including nested ones, readonly.\ntype ImmutableUser = DeepReadonly<User>;\n\nconst user: ImmutableUser = {\n  id: 1,\n  name: 'Alice',\n  settings: {\n    theme: 'dark',\n    notificationsEnabled: true,\n  },\n};\n// user.name = 'Bob'; // Error: Cannot assign to 'name' because it is a read-only property.\n// user.settings.theme = 'light'; // Error: Cannot assign to 'theme' because it is a read-only property.\n\n// Optional<T, K>: Makes specific keys K in T optional.\ntype UserWithOptionalId = Optional<User, 'id'>;\nconst newUser: UserWithOptionalId = {\n  name: 'Bob',\n  settings: { theme: 'light', notificationsEnabled: false },\n};\n\n// Falsy: Represents common \"falsy\" values in JavaScript.\nfunction isFalsyValue(value: unknown): value is Falsy {\n  return !value; // A simple runtime check for demonstration\n}\nconsole.log(`Is 0 falsy? ${isFalsyValue(0)}`); // true\nconsole.log(`Is 'hello' falsy? ${isFalsyValue('hello')}`); // false\n\n// Primitive: Represents non-object types.\ntype MyPrimitive = Primitive;\nlet p: MyPrimitive = 123;\np = 'hello';\np = true;\n// p = { a: 1 }; // Error: Type '{ a: number; }' is not assignable to type 'Primitive'.\n\n// Nullish: Represents null or undefined.\ntype MaybeString = string | Nullish;\nconst s1: MaybeString = \"hello\";\nconst s2: MaybeString = null;\nconst s3: MaybeString = undefined;\n// const s4: MaybeString = false; // Error: Type 'false' is not assignable to type 'string | null | undefined'.\n\n// This quickstart demonstrates how to use several key utility types from the `utility-types`\n// library, including `DeepReadonly` for deep immutability, `Optional` for making specific\n// properties optional, and `Falsy`, `Primitive`, and `Nullish` for working with common\n// JavaScript value classifications at the type level.","lang":"typescript","description":"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."},"warnings":[{"fix":"Ensure your project's TypeScript version meets the requirements of the `utility-types` major version you are using. Upgrade TypeScript if necessary.","message":"utility-types has specific TypeScript version requirements for its major versions. v3.x.x requires TypeScript v3.1+, v2.x.x requires TypeScript v2.8.1+, and v1.x.x requires TypeScript v2.7.2+. Using an incompatible version of TypeScript will likely lead to compilation errors and unexpected type behavior.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Replace all instances of `Falsey` with `Falsy` in your codebase.","message":"As of v3.9.0, the type alias `Falsey` has been deprecated in favor of `Falsy`. While `Falsey` is kept for backward compatibility, new code should use `Falsy` to ensure future compatibility and align with the updated naming convention.","severity":"deprecated","affected_versions":">=3.9.0"},{"fix":"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.","message":"In v3.6.1, the `Omit` implementation was reverted to an older version due to a bug in TypeScript v3.5. Users upgrading from v3.6.0 or using TypeScript v3.5 might experience subtle changes in `Omit`'s behavior or type inference. It is recommended to update TypeScript to a more recent stable version if possible.","severity":"gotcha","affected_versions":">=3.6.1"},{"fix":"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.","message":"In v3.10.0, `undefined` was removed from the `keyof` result of `(Pick|Omit)ByValue(Exact)`. This is a type-level breaking change that could alter type inference and assignments for code relying on the previous behavior where `undefined` might have been included in the key types.","severity":"breaking","affected_versions":">=3.10.0"},{"fix":"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.","message":"As a library deeply integrated with TypeScript's evolving type system, even minor version bumps can sometimes introduce subtle breaking changes in type inference or edge-case behavior due to refinements or bug fixes (e.g., changes to `Primitive`, `FunctionKey`, `NonFunctionKeys`). Always review release notes when upgrading, especially for significant minor versions, to understand potential impacts.","severity":"gotcha","affected_versions":">=3.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Add an import statement for the specific type: `import { Primitive } from 'utility-types';`","cause":"A utility type like `Primitive` was used without an explicit `import` statement.","error":"Cannot find name 'Primitive'."},{"fix":"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.","cause":"Attempting to assign a `null` or `undefined` value where a non-`Nullish` type is expected, potentially misusing `Falsy` when a stricter `Nullish` or custom union is needed. While `Falsy` includes `null` and `undefined`, specific contexts might expect only non-`Nullish` values.","error":"Type 'null' is not assignable to type 'string'."},{"fix":"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>`.","cause":"An attempt was made to modify a property of an object wrapped with `DeepReadonly`, which recursively makes all properties immutable.","error":"Property 'someProperty' is readonly and cannot be assigned to in type 'DeepReadonly<T>'."}],"ecosystem":"npm"}