Merge two TypeScript object types into one without writing complex custom type logic
Make specific fields of an existing type optional or required without redefining the whole type
Extract the exact return type of a function to reuse it elsewhere in your code
Filter or remap the members of a union type using built-in utilities
Requires TypeScript 4.1 or higher with strict mode enabled for best results.
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.
← millsp on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.