ts-essentials vs ts-toolbelt
TypeScript Utility Libraries Comparison
1 Year
ts-essentialsts-toolbelt
What's TypeScript Utility Libraries?

TypeScript utility libraries provide developers with a set of tools and types that enhance the TypeScript experience. They offer a range of utility types, functions, and helpers designed to make TypeScript development more efficient and robust. These libraries aim to simplify common tasks, improve type safety, and provide advanced type manipulation capabilities, making them essential for TypeScript developers looking to leverage the full power of the language.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
ts-essentials4,720,2313,942243 kB2216 days agoMIT
ts-toolbelt4,373,9716,990-724 years agoApache-2.0
Feature Comparison: ts-essentials vs ts-toolbelt

Utility Types

  • ts-essentials:

    ts-essentials provides a variety of utility types that enhance type safety and simplify common tasks. It includes types like 'Nullable', 'Optional', and 'Readonly', which help developers manage data structures more effectively and reduce runtime errors by enforcing stricter type checks.

  • ts-toolbelt:

    ts-toolbelt offers an extensive collection of utility types that go beyond basic utilities. It includes advanced types for deep manipulation, such as 'Merge', 'Path', and 'Tuple', allowing developers to create complex type transformations and combinations that can significantly enhance type safety and flexibility.

Type Safety

  • ts-essentials:

    ts-essentials emphasizes type safety by providing types that help prevent common programming errors. Its utilities are designed to ensure that developers can work with types in a way that minimizes the risk of runtime issues, making it a great choice for projects where type integrity is critical.

  • ts-toolbelt:

    ts-toolbelt also focuses on type safety but offers a broader range of tools that allow for more intricate type definitions. It enables developers to create highly specific types that can adapt to various scenarios, thus enhancing the robustness of the codebase.

Learning Curve

  • ts-essentials:

    ts-essentials has a relatively gentle learning curve, making it accessible for developers who are new to TypeScript or utility libraries. Its straightforward API and well-documented features allow for quick adoption and integration into projects.

  • ts-toolbelt:

    ts-toolbelt has a steeper learning curve due to its extensive feature set and advanced type manipulation capabilities. Developers may need to invest more time to fully understand and utilize its functionalities, making it better suited for those with more experience in TypeScript.

Performance

  • ts-essentials:

    ts-essentials is optimized for performance with a focus on providing essential utilities without adding unnecessary overhead. This makes it suitable for projects where performance is a key concern, ensuring that type checks and utilities do not slow down the development process.

  • ts-toolbelt:

    ts-toolbelt, while powerful, can introduce complexity that may impact performance, especially in large codebases. Developers should be mindful of the trade-offs when using its advanced features, as they may lead to more complex type evaluations.

Extensibility

  • ts-essentials:

    ts-essentials is designed to be extensible, allowing developers to create custom utility types and functions that fit their specific needs. This flexibility makes it a good choice for teams that require tailored solutions for their TypeScript projects.

  • ts-toolbelt:

    ts-toolbelt excels in extensibility, providing a framework for creating highly reusable and composable types. Its functional programming approach encourages developers to build upon existing utilities, fostering a culture of code reuse and modularity.

How to Choose: ts-essentials vs ts-toolbelt
  • ts-essentials:

    Choose ts-essentials if you need a library that offers a comprehensive set of utility types and functions focused on enhancing type safety and providing essential utilities for TypeScript development. It is particularly useful for projects that require strong type definitions and a straightforward approach to common programming tasks.

  • ts-toolbelt:

    Choose ts-toolbelt if you are looking for a more extensive and flexible set of utility types that allow for advanced type manipulation and functional programming patterns. It is ideal for developers who need powerful tools for complex type operations and want to leverage a more functional programming style in their TypeScript code.

README for ts-essentials

ts-essentials

ts-essentials

All essential TypeScript types in one place 🤙

Version Downloads Build status Telegram Software License codechecks.io

Install

npm install --save-dev ts-essentials

👉 We require typescript>=4.5. If you're looking for support for older TS versions, please have a look at the TypeScript dependency table

👉 As we really want types to be stricter, we require enabled strictNullChecks in your project

API

ts-essentials is a set of high-quality, useful TypeScript types that make writing type-safe code easier.

Basic

Utility types

  • AsyncOrSync<Type> - Constructs a type with Type or PromiseLike<Type>
  • AsyncOrSyncType<Type> - Unwraps AsyncOrSync type
  • Dictionary<Type, Keys?> - Constructs a required object type which property keys are Keys (string by default) and which property values are Type
  • Merge<Object1, Object2> - Constructs a type by picking all properties from Object1 and Object2. Property values from Object2 override property values from Object1 when property keys are the same
  • MergeN<Tuple> - Constructs a type by merging objects with type Merge in tuple Tuple recursively
  • Newable<ReturnType> - Constructs a class type with constructor which has return type ReturnType
  • NonNever<Type> - Constructs a type by picking all properties from type Type which values don't equal to never
  • OmitProperties<Type, Value> - Constructs a type by picking all properties from type Type and removing those properties which values equal to Value
  • Opaque<Type, Token> - Constructs a type which is a subset of Type with a specified unique token Token
  • PathValue<Type, Path> - Constructs a path value for type Type and path Path
  • Paths<Type> - Constructs a union type by picking all possible paths for type Type
  • PickProperties<Type, Value> - Constructs a type by picking all properties from type Type which values equal to Value
  • SafeDictionary<Type, Keys?> - Constructs an optional object type which property keys are Keys (string by default) and which property values are Type
  • UnionToIntersection<Union> - Constructs a intersection type from union type Union
  • ValueOf<Type> - Constructs a type for type Type and equals to a primitive for primitives, array elements for arrays, function return type for functions or object property values for objects
  • XOR<Type1, Type2, Type3?, ..., Type50?> - Construct a type which is assignable to either type Type1, Type2 but not both. Starting in ts-essentials@10, it supports up to 50 generic types.

Mark wrapper types

  • MarkOptional<Type, Keys> - Constructs a type by picking all properties from type Type where properties Keys are set as optional, meaning they aren't required
  • MarkReadonly<Type, Keys> - Constructs a type by picking all properties from type Type where properties Keys are set to readonly, meaning they cannot be reassigned
  • MarkRequired<Type, Keys> - Constructs a type by picking all properties from type Type where properties Keys are set as required
  • MarkWritable<Type, Keys> - Constructs a type by picking all properties from type Type where properties Keys remove readonly modifier, meaning they can be reassigned

Deep wrapper types

  • Buildable<Type> - Constructs a type by combining DeepPartial and DeepWritable, meaning all properties from type Type are recursively set as non-readonly and optional, meaning they can be reassigned and aren't required
  • DeepMarkOptional<Type, KeyPathUnion> - Constructs a type by picking all properties from type Type where properties by paths KeyPathUnion are set as optional. To mark properties optional on one level, use MarkOptional<Type, Keys>.
  • DeepMarkRequired<Type, KeyPathUnion> - Constructs a type by picking all properties from type Type where properties by paths KeyPathUnion are set as required. To mark properties required on one level, use MarkRequired<Type, Keys>.
  • DeepNonNullable<Type> - Constructs a type by picking all properties from type Type recursively and exclude null and undefined property values from all of them. To make properties non-nullable on one level, use NonNullable<Type>
  • DeepNullable<Type> - Constructs a type by picking all properties from type Type recursively and include null property values for all of them
  • DeepOmit<Type, Filter> - Constructs a type by picking all properties from type Type and removing properties which values are never or true in type Filter. If you'd like type Filter to be validated against a structure of Type, please use StrictDeepOmit<Type, Filter>.
  • DeepPartial<Type> - Constructs a type by picking all properties from type Type recursively and setting them as optional, meaning they aren't required. To make properties optional on one level, use Partial<Type>
  • DeepPick<Type, Filter> - Constructs a type by picking set of properties, which have property values never or true in type Filter, from type Type. If you'd like type Filter to be validated against a structure of Type, please use StrictDeepPick<Type, Filter>.
  • DeepReadonly<Type> - Constructs a type by picking all properties from type Type recursively and setting readonly modifier, meaning they cannot be reassigned. To make properties readonly on one level, use Readonly<Type>
  • DeepRequired<Type> - Constructs a type by picking all properties from type Type recursively and setting as required. To make properties required on one level, use Required<Type>
  • DeepUndefinable<Type> - Constructs a type by picking all properties from type Type recursively and include undefined property values for all of them
  • DeepWritable<Type> - Constructs a type by picking all properties from type Type recursively and removing readonly modifier, meaning they can be reassigned. To make properties writable on one level, use Writable<Type>
  • StrictDeepOmit<Type, Filter> - Constructs a type by picking all properties from type Type and removing properties which values are never or true in type Filter. The type Filter is validated against a structure of Type.
  • StrictDeepPick<Type, Filter> - Constructs a type by picking set of properties, which have property values never or true in type Filter, from type Type. The type Filter is validated against a structure of Type.

Key types

  • OptionalKeys<Type> - Constructs a union type by picking all optional properties of object type Type
  • PickKeys<Type, Value> - Constructs a union type by picking all properties of object type Type which values are assignable to type Value
  • ReadonlyKeys<Type> - Constructs a union type by picking all readonly properties of object type Type, meaning their values cannot be reassigned
  • RequiredKeys<Type> - Constructs a union type by picking all required properties of object type Type
  • WritableKeys<Type> - Constructs a union type by picking all writable properties of object type Type, meaning their values can be reassigned

Type checkers

  • Exact<Type, Shape> - Returns Type when type Type and Shape are identical. Otherwise returns never
  • IsAny<Type> - Returns true when type Type is any. Otherwise returns false
  • IsNever<Type> - Returns true when type Type is never. Otherwise returns false
  • IsUnknown<Type> - Returns true when type Type is unknown. Otherwise returns false
  • IsTuple<Type> - Returns Type when type Type is tuple. Otherwise returns never
  • NonEmptyObject<Object> - Returns Object when Object has at least one key. Otherwise returns never

Arrays and Tuples

Change case

Function types

Utility functions

⚠️ Make sure you add ts-essentials to your dependencies (npm install --save ts-essentials) to avoid runtime errors

Search

When one of utility types is known by a different name, kindly ask adding it here for the better search.

Built-in types

TypeScript provides several utility types to facilitate common type transformations. These utilities are available globally.

  • Awaited<Type> - This type is meant to model operations like await in async functions, or the .then() method on Promises - specifically, the way that they recursively unwrap Promises
  • Capitalize<StringType> - Converts the first character in the string to an uppercase equivalent
  • ConstructParameters<Type> - Constructs a tuple or array type from the types of a constructor function type Type
  • Exclude<UnionType, ExcludedMembers> - Constructs a type by excluding from UnionType all union members that are assignable to ExcludedMembers
  • Extract<Type, Union> - Constructs a type by extracting from Type all union members that are assignable to Union
  • InstanceType<Type> - Constructs a type consisting of the instance type of a constructor function in Type
  • Lowercase<StringType> - Converts each character in the string to the lowercase equivalent
  • NonNullable<Type> - Constructs a type by excluding null and undefined from Type
  • Omit<Type, Keys> - Constructs a type by picking all properties from Type and then removing Keys
  • Parameters<Type> - Constructs a tuple type from the types used in the parameters of a function type Type
  • Partial<Type> - Constructs a type with all properties of Type set to optional
  • Pick<Type, Keys> - Constructs a type by picking the set of properties Keys from Type
  • Readonly<Type> - Constructs a type with all properties of Type set to readonly, meaning the properties of the constructed type cannot be reassigned
  • Record<Keys, Type> - Constructs an object type whose property keys are Keys and whose property values are Type
  • Required<Type> - Constructs a type consisting of all properties of Type set to required
  • ReturnType<Type> - Constructs a type consisting of the return type of function type Type parameter
  • Uncapitalize<StringType> - Converts the first character in the string to a lowercase equivalent
  • Uppercase<StringType> - Converts each character in the string to the uppercase version

TypeScript dependency table

| ts-essentials | typescript / type of dependency | | --------------- | ------------------------------------------------------------------------------------- | | ^10.0.0 | ^4.5.0 / peer optional | | ^9.4.0 | ^4.1.0 / peer optional | | ^8.0.0 | ^4.1.0 / peer | | ^5.0.0 | ^3.7.0 / peer | | ^3.0.1 | ^3.5.0 / peer | | ^1.0.1 | ^3.2.2 / dev | | ^1.0.0 | ^3.0.3 / dev |

Limitations

  • This project doesn't use extends Constraints on infer Type Variables as it's introduced in TypeScript 4.7, but currently ts-essentials supports versions below, e.g. TypeScript 4.5. Read more in https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-7.html#extends-constraints-on-infer-type-variables

Contributors

Special shout-out to active contributors:

And thanks goes to these wonderful people:

💻 - contributions, i.e. links to commits by the user on this project

Contributions of any kind welcome! Read more