ts-essentials vs tsdef vs ts-toolbelt
TypeScript Utility Libraries
ts-essentialstsdefts-toolbelt

TypeScript Utility Libraries

TypeScript utility libraries provide developers with a set of tools and types that enhance the TypeScript experience, making it easier to work with complex types, improve code quality, and streamline development processes. These libraries often include utility types, type-safe functions, and advanced type manipulation capabilities, which can significantly reduce boilerplate code and improve type safety in TypeScript projects.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
ts-essentials3,486,4494,059243 kB299 months agoMIT
tsdef39,21259947 kB19-MIT
ts-toolbelt07,134-725 years agoApache-2.0

Feature Comparison: ts-essentials vs tsdef vs ts-toolbelt

Type Utilities

  • ts-essentials:

    ts-essentials offers a variety of utility types that simplify common TypeScript tasks, such as creating optional properties, extracting types from objects, and more. This library is designed to enhance the developer experience by providing easy-to-use utilities that reduce boilerplate code.

  • tsdef:

    tsdef focuses on defining types and ensuring type safety through validation. It provides utilities for creating and managing types in a way that emphasizes clarity and correctness, making it easier to maintain type integrity throughout the codebase.

  • ts-toolbelt:

    ts-toolbelt provides an extensive collection of advanced utility types that allow for complex type manipulations, such as deep merging, conditional types, and tuple manipulations. This library is aimed at developers who need powerful tools to work with intricate type scenarios.

Learning Curve

  • ts-essentials:

    ts-essentials is designed to be user-friendly, making it accessible for developers of all skill levels. Its straightforward API and clear documentation help users quickly understand how to implement the utilities in their projects.

  • tsdef:

    tsdef is relatively easy to learn, especially for developers familiar with TypeScript's type system. Its focus on type definitions and validation makes it intuitive for those who prioritize type safety in their projects.

  • ts-toolbelt:

    ts-toolbelt has a steeper learning curve due to its advanced features and complex type manipulations. It is best suited for experienced TypeScript developers who are comfortable with the intricacies of the type system and want to leverage its full capabilities.

Extensibility

  • ts-essentials:

    ts-essentials is designed to be easily extensible, allowing developers to create custom utility types or functions as needed. This flexibility makes it a good choice for projects that may require specific enhancements to the provided utilities.

  • tsdef:

    tsdef is less focused on extensibility compared to the other libraries, as it primarily serves the purpose of defining and validating types. However, it can still be integrated into larger systems where type definitions need to be managed.

  • ts-toolbelt:

    ts-toolbelt is highly extensible and encourages developers to build upon its advanced type utilities. Its modular design allows for easy integration of custom types and utilities, making it suitable for large-scale applications with diverse type requirements.

Community Support

  • ts-essentials:

    ts-essentials has a growing community and is well-documented, which helps developers find support and resources easily. Its popularity is increasing, making it a reliable choice for TypeScript projects.

  • tsdef:

    tsdef has a smaller community compared to the other two packages, but it is well-maintained and offers sufficient documentation to assist users. It is particularly useful for niche applications that require strict type definitions.

  • ts-toolbelt:

    ts-toolbelt has a strong community of advanced TypeScript users and contributors. Its extensive documentation and examples provide valuable resources for developers looking to utilize its advanced features effectively.

Performance

  • ts-essentials:

    ts-essentials is optimized for performance, providing lightweight utilities that do not add significant overhead to TypeScript projects. This makes it suitable for applications where performance is a key concern.

  • tsdef:

    tsdef is designed to be efficient in managing type definitions and validations, ensuring that performance remains optimal even in larger applications where type integrity is crucial.

  • ts-toolbelt:

    ts-toolbelt, while powerful, can introduce complexity that may affect performance in certain scenarios, especially with deeply nested types. Developers should be mindful of performance implications when using its advanced features.

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

  • ts-essentials:

    Choose ts-essentials if you need a library that provides a comprehensive set of utility types and functions that are easy to use and integrate into existing TypeScript projects. It is particularly useful for developers looking for a straightforward approach to enhancing type safety and code quality without a steep learning curve.

  • tsdef:

    Choose tsdef if you are looking for a library focused on defining and validating TypeScript types in a more structured way. It is particularly useful for projects that require strict type definitions and validation, making it a good fit for applications where type integrity is critical.

  • ts-toolbelt:

    Choose ts-toolbelt if you require advanced type manipulation capabilities and a rich set of utility types. It is ideal for projects that demand high flexibility and complex type operations, making it suitable for experienced TypeScript developers who want to leverage the full power of TypeScript's type system.

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-essentialstypescript / 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

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