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

TypeScript utility libraries provide a collection of types and functions that enhance the TypeScript development experience by offering additional type safety, utility types, and helper functions. These libraries aim to simplify common tasks and improve code quality, making it easier for developers to work with TypeScript's static typing system. Each library has its own unique features and design philosophies, catering to different needs in TypeScript development.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
ts-essentials4,844,7383,942243 kB2215 days agoMIT
ts-toolbelt4,306,6936,989-724 years agoApache-2.0
ts-extras20,31261625.7 kB183 months agoMIT
Feature Comparison: ts-essentials vs ts-toolbelt vs ts-extras

Utility Types

  • ts-essentials:

    ts-essentials provides a set of essential utility types that enhance TypeScript's built-in types. It includes types like 'Nullable', 'Optional', and 'Readonly', which help in creating more expressive and type-safe code without overwhelming the developer with too many options.

  • ts-toolbelt:

    ts-toolbelt is known for its extensive collection of utility types, including advanced features like 'Tuple', 'Object', and 'Function' manipulations. It provides a rich set of types that can handle complex scenarios, making it a go-to choice for developers who need powerful type utilities.

  • ts-extras:

    ts-extras offers a broader range of utility types, including advanced types for manipulating tuples, objects, and unions. It provides types like 'Merge', 'PickBy', and 'Omit', which allow for more complex type transformations and help in creating cleaner and more maintainable code.

Functionality

  • ts-essentials:

    ts-essentials focuses on providing simple and essential functions that enhance TypeScript's capabilities. It includes utility functions for array manipulation, object handling, and type checking, making it easy to perform common tasks without adding unnecessary complexity.

  • ts-toolbelt:

    ts-toolbelt offers a rich set of functions that support advanced programming paradigms, including functional programming techniques. It provides utilities for composing functions, currying, and more, making it suitable for developers who want to leverage TypeScript's capabilities to the fullest.

  • ts-extras:

    ts-extras includes a wider range of utility functions that cater to various needs, such as deep cloning, merging objects, and more. It aims to provide a comprehensive toolkit for developers who require additional functionality beyond the basics.

Learning Curve

  • ts-essentials:

    ts-essentials has a gentle learning curve, making it accessible for developers who are new to TypeScript. Its straightforward API and focus on essential utilities allow for quick adoption without overwhelming users with complexity.

  • ts-toolbelt:

    ts-toolbelt has a steeper learning curve due to its extensive features and advanced type manipulations. It is best suited for experienced TypeScript developers who are comfortable with complex type systems and functional programming concepts.

  • ts-extras:

    ts-extras has a moderate learning curve, as it introduces more advanced concepts and utilities. Developers may need to familiarize themselves with additional types and functions, but it remains approachable for those with some TypeScript experience.

Extensibility

  • ts-essentials:

    ts-essentials is designed to be lightweight and minimal, which makes it less extensible compared to other libraries. However, its simplicity allows developers to easily integrate it into existing projects without significant overhead.

  • ts-toolbelt:

    ts-toolbelt is highly extensible, providing a robust framework for developers to create custom types and utilities. Its comprehensive API allows for extensive customization, making it suitable for large-scale applications that require tailored solutions.

  • ts-extras:

    ts-extras offers moderate extensibility, allowing developers to build upon its utility types and functions. It provides a solid foundation for creating custom utilities while maintaining a balance between simplicity and functionality.

Community Support

  • ts-essentials:

    ts-essentials has a smaller community compared to the other libraries, which may result in limited resources and examples. However, its simplicity and focus on essentials make it easy to understand and use without extensive community support.

  • ts-toolbelt:

    ts-toolbelt boasts a strong community and extensive documentation, providing ample resources for developers. Its popularity among advanced TypeScript users ensures that there are plenty of examples, tutorials, and discussions available.

  • ts-extras:

    ts-extras has a growing community and offers a decent amount of resources, including documentation and examples. This makes it easier for developers to find help and learn from others who have used the library.

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

    Choose ts-essentials if you need a lightweight library that offers essential utility types and functions to enhance TypeScript's type system without adding unnecessary complexity. It is ideal for projects that require basic type utilities and want to keep dependencies minimal.

  • ts-toolbelt:

    Choose ts-toolbelt if you need a comprehensive and powerful collection of utility types and functions that cover a wide range of use cases. It is designed for advanced TypeScript users who require extensive type manipulation capabilities and want to leverage TypeScript's full potential.

  • ts-extras:

    Choose ts-extras if you are looking for a more extensive set of utility types and functions that go beyond the basics. This library provides additional features that can help with more complex type manipulations and improve overall code quality, making it suitable for larger projects.

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