gitmyhub

ts-toolbelt

TypeScript ★ 7.1k updated 1y ago

👷 TypeScript's largest type utility library

ts-toolbelt is a TypeScript library of 200+ ready-made type utilities for merging, filtering, and transforming object, function, string, and union types, adding zero runtime code to your app.

TypeScriptnpmsetup: easycomplexity 2/5

ts-toolbelt is a collection of over 200 utility types for TypeScript, a programming language that adds type annotations to JavaScript. In TypeScript, types describe the shape of data: what fields an object has, what a function accepts and returns, and so on. As programs grow, developers often need to transform or combine those types in sophisticated ways, and doing that from scratch can be complex. ts-toolbelt provides a ready-made library of those transformations.

The library is organized around TypeScript's core concepts: object types, list types (arrays), function types, string types, union types, class types, boolean types, and number types. For each category there are many specific utilities. For example, you can merge two object types together, make certain fields optional, extract the return type of a function, split a string type into its parts, or filter the members of a union. These are things TypeScript supports in principle, but the logic to do them cleanly can take many lines of code to write yourself.

The library describes itself as similar to utility libraries like lodash or ramda, but applied to the type level rather than to runtime data. Installing it does not add anything that runs in your application; it only adds type definitions that help the TypeScript compiler catch mistakes and understand your code better.

Installation is through npm, the standard JavaScript package manager. The library requires TypeScript version 4.1 or higher and works best with strict type checking enabled. It has a full documentation site with entries for each utility, organized by category.

Where it fits