utility-types: a type level catalogue for TypeScript projects
Collection of utility types, complementing TypeScript built-in mapped types and aliases (think "lodash" for static types).
At a glance
- What is it?
- utility-types collects generic types so TypeScript projects stop copying mapped types between codebases, and also exports a small set of runtime type guards. What you get is a wide catalogue with a compiler floor of TypeScript 3.1 and a published build that is older than the branch head.
- Who is it for?
- Adopt it if several services keep redefining the same DeepPartial or PickByValue helper and you want one tested copy. Skip it if your compiler is older than 3.1, if Omit and DeepReadonly are all you need, or if you want runtime checks on values coming out of JSON.parse.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Activity is slowing. The repository last received commits 6 months ago.
- What is it written in?
- Mainly TypeScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- piotrwitek/utility-types5,765 ★ · +2
| Repository | 2026-09-23 | 2026-11-25 |
|---|---|---|
| piotrwitek/utility-types | 5.8k | 5.8k |
2 Stars in the last 63 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
One install command, zero runtime dependencies
Install it the way you install any other type package. The README gives both package managers and there is nothing to configure afterwards:
# NPM
npm install utility-types
# YARN
yarn add utility-typesThe `dependencies` block in package.json is empty, and the stated goal is no third-party dependencies at all. `main` points at `dist/index.js`, `types` at `dist/index.d.ts`, and `engines` asks for node >= 4. Type-only imports are erased by TypeScript, but the published JavaScript also exports runtime guards including isFalsy, isNullish and isPrimitive; using those adds runtime code.
First use looks like this. The parameter is declared with the union that the guard is going to narrow:
const consumer = (param: Falsy | string): string => {
if (isFalsy(param)) {
// typeof param === Falsy
return String(param) + ' was Falsy';
}
// typeof param === string
return param.toString();
};Inside the `if` the parameter is `Falsy`, after it `string`. That is the whole mechanism: type annotations are erased, while the isFalsy call is runtime JavaScript. The version floor matters before you install, since the compatibility notes put v3.x.x on TypeScript v3.1+.
isPrimitive, isFalsy and isNullish narrow a parameter mid function
These three sit under Aliases & Type Guards, next to the plain unions they check. `Primitive` covers `string | number | bigint | boolean | symbol | null | undefined`, `Falsy` covers `false | "" | 0 | null | undefined`, and `Nullish` covers `null | undefined`. For a primitive the README points at `typeof` as the singular runtime test.
The primitive guard handles a parameter that may itself be an array:
const consumer = (param: Primitive[] | Primitive): string => {
if (isPrimitive(param)) {
// typeof param === Primitive
return String(param) + ' was Primitive';
}
// typeof param === Primitive[]
const resultArray = param
.map(consumer)
.map(rootString => '\n\t' + rootString);
return resultArray.reduce((comm, newV) => comm + newV, 'this was nested:');
};`isNullish` is the same shape with `Nullish | string` as the parameter type. One gap is documented in place: `Falsy` leaves out `NaN`, because `NaN` cannot be written as a type literal, so a `Falsy` guard does not cover a value that JavaScript treats as falsy.
Two limits follow. The guards cover only these three unions, so a payload from `JSON.parse` or an HTTP response still needs a guard you write yourself. And a guard can only narrow a parameter that already carries a type.
SetDifference and SetComplement wrap Exclude and Extract
The union operators group mixes library names with names the compiler already ships. `SetIntersection<A, B>` is annotated as the same as `Extract`, `SetDifference<A, B>` as the same as `Exclude`, and `SetComplement<A, A1>` sits beside them. `Extract`, `Exclude` and `NonNullable` are all marked built-in, with `NonUndefined<T>` as the package's own contribution next to them.
That annotation continues into the object operators, where `Partial`, `Readonly`, `Pick` and `Omit` are flagged built-in while `DeepPartial`, `DeepRequired` and `DeepReadonly` are not, and into the special operators, where `ReturnType` and `InstanceType` are flagged while `PromiseType` and `Unionize` are not. The stated reason for the common group is that these types are complementary to the mapped types the language gives you, so you stop copying helpers between projects.
The corollary is a catalogue that duplicates the standard library on purpose. On TypeScript 3.1 and newer, a `SetDifference` call is a differently spelled `Exclude`, which matters when you decide whether a codebase needs the dependency at all.
FunctionKeys and DeepPartial reach parts the built ins ignore
Built-in `Partial` and `Readonly` are shallow. `DeepPartial`, `DeepRequired` and `DeepReadonly` are the answer to that, applying the change through nested object types instead of one level.
Alongside them sit key set operators that name keys themselves: `FunctionKeys<T>` with `NonFunctionKeys<T>`, `MutableKeys<T>` with `ReadonlyKeys<T>`, `RequiredKeys<T>` with `OptionalKeys<T>`, and `UnionKeys<U>`. They are useful when the shape you want reads as the mutable keys of T rather than a hand written union of string literals.
If your nested types are recursive, or hold arrays and tuples, test the depth of the walk in your own codebase before you rely on it.
PickByValue filters on the value type, not the key
`Pick<T, K>` and `Omit<T, K>` select by key. This package adds the same operations by value: `PickByValue<T, ValueType>` and `PickByValueExact<T, ValueType>` keep the properties whose value type matches, while `OmitByValue<T, ValueType>` and `OmitByValueExact<T, ValueType>` drop them. The plain and exact pairs are listed as four separate entries.
Reshaping follows the same pattern: `Intersection<T, U>`, `Diff<T, U>`, `Subtract<T, T1>`, `Overwrite<T, U>`, `Assign<T, U>` and `ValuesType<T>`. Several of those names sit close together in the list, so a reader picks from the catalogue rather than inferring behaviour from the wording.
That proximity is the practical risk. A wrong guess surfaces as a compile error at the point of use.
The Flow block targets migration, not new TypeScript work
One group exists for code arriving from Flow: `$Keys<T>`, `$Values<T>`, `$ReadOnly<T>`, `$Diff<T, U>`, `$PropertyType<T, K>`, `$ElementType<T, K>`, `$Call<T>`, `$Shape<T>`, `$NonMaybeType<T>`, `Class<T>` and `mixed`. The stated purpose is to make moving a Flow codebase to TypeScript easier. For a TypeScript project that never used Flow, those eleven entries are weight you scan past.
The repository root also holds two directories the type list never mentions. `experimental/` and `utils/` sit next to `src/`, alongside `.prettierrc`, `tslint.json`, `jest.config.json`, `tsconfig.json` and `tsconfig.build.json`.
The funding and contribution route is explicit as well: issues can carry a bounty through the IssueHunt platform, and CONTRIBUTING.md is the guide named before anyone opens a pull request.
A pre push hook runs prettier, tslint, tsc and the snapshot test
Type correctness is enforced by tooling rather than by hand. The `husky` block wires a `pre-push` hook to four scripts in sequence:
npm run prettier:fix && npm run lint && npm run tsc && npm run test:update`npm run lint` is `tslint --project ./tsconfig.json` and `npm run tsc` is `tsc -p . --noEmit`. Formatting has its own gate, since `prettier` runs `prettier --list-different 'src/**/*.ts'`, prints a message pointing at `npm run prettier:fix`, and exits 1 when a file differs. The `ci-check` script chains the non fixing versions instead and ends in `npm run test`.
That test is two stages:
jest --config jest.config.json && dts-jest-remap ./src/*.spec.ts --rename {{basename}}.snap.{{extname}} --checkThe spec files live in `src/`, and the remap step compares type level assertions against committed snapshots. `test:update` adds `--no-cache -u` and rewrites them. Before publishing, `prepublishOnly` runs `npm run reinstall && npm run ci-check && npm run build`, with `build` being `tsc -p ./tsconfig.build.json --outDir dist/`.
npm still serves 3.11.0 from January 2024
The release list shows v3.11.0 on 2024-01-18, v3.10.0 on 2019-11-09 and v3.9.0 on 2019-10-28, so the gap between the last two published versions is over four years. The repository is not archived, and the last push to the `master` branch was on 2026-05-09, which means branch head and published package are different states of the code. Anything merged since January 2024 is not in what `npm install utility-types` hands you.
One entry is kept on purpose: `getReturnOfExpression()` sits under Deprecated API (use at own risk), with a note that from TypeScript v2.0 the type level `ReturnType` is the better choice.
The compiler floor is the other thing to check before adopting. Compatibility notes put v3.x.x on TypeScript v3.1+, v2.x.x on v2.8.1+ and v1.x.x on v2.7.2+, while the dev toolchain stays pinned to typescript 3.7.2, jest 24.9.0 and tslint 5.20.1.
Editorial conclusion
Adopt it if several services keep redefining the same DeepPartial or PickByValue helper and you want one tested copy. Skip it if your compiler is older than 3.1, if Omit and DeepReadonly are all you need, or if you want runtime checks on values coming out of JSON.parse. Before wiring it in, confirm every type you need already exists in the published 3.11.0 build rather than only on the master branch.
Frequently asked questions
What is utility types in a TypeScript project?
It is a collection of generic types that complement TypeScript built-in mapped types and aliases, described as lodash for static types. It is type level only with an empty dependencies block, MIT licensed, and the published npm release is v3.11.0.
What are utility types in TS, as utility-types groups them?
The catalogue is split into Aliases and Type Guards, Union operators, Object operators, Special operators, Flow's Utility Types, and a Deprecated API section. Members such as Partial, Pick, Omit, Extract, ReturnType and InstanceType are annotated as built-in.
What does "utility type" mean in the utility-types catalogue?
It means a helper that rewrites another type rather than a value at runtime. utility-types applies that idea to DeepPartial, DeepReadonly, PickByValue, OmitByValueExact, Brand and UnionToIntersection, so the definitions can be imported instead of rewritten in each project.
What are five types of utilities that utility-types adds?
Five of them: DeepPartial, DeepRequired and DeepReadonly for nested objects, plus PickByValue and OmitByValueExact for selecting properties by value type rather than by key.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/piotrwitek-utility-types)Star history chart for your README
[](https://hysenlabs.com/projects/piotrwitek-utility-types)Was this useful?