tslib vs ts-helpers
TypeScript Utility Libraries Comparison
1 Year
tslibts-helpers
What's TypeScript Utility Libraries?

TypeScript utility libraries are designed to enhance the TypeScript development experience by providing additional functionality, optimizing code generation, and improving runtime performance. These libraries help developers manage TypeScript's advanced features, such as decorators, async/await, and other syntactic sugar, while also ensuring that the generated JavaScript is efficient and easy to maintain. By utilizing these libraries, developers can streamline their workflows, reduce boilerplate code, and leverage TypeScript's capabilities more effectively.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
tslib251,632,8481,28490.4 kB554 months ago0BSD
ts-helpers29,21557-28 years agoMIT
Feature Comparison: tslib vs ts-helpers

Purpose and Functionality

  • tslib:

    tslib is a runtime library for TypeScript that contains helper functions that are used by TypeScript's emitted code. It aims to reduce the size of the output JavaScript by providing shared implementations of common TypeScript features, such as spread operators and async functions.

  • ts-helpers:

    ts-helpers provides a minimal set of helper functions that TypeScript uses to implement certain language features. It is designed to be lightweight and is particularly useful for projects that need to support older JavaScript environments without introducing significant overhead.

Bundle Size

  • tslib:

    tslib is larger than ts-helpers but provides a more extensive set of utilities. While it may increase the bundle size slightly, it optimizes the generated code by reusing common functions, which can lead to better performance in larger applications.

  • ts-helpers:

    ts-helpers is designed to be very small, making it suitable for projects where minimizing bundle size is critical. It only includes the necessary helpers that are required for TypeScript features, ensuring that the footprint remains minimal.

Compatibility

  • tslib:

    tslib is designed to work seamlessly with modern TypeScript projects and is especially useful when leveraging advanced features like async/await. It is recommended for projects that require compatibility with the latest TypeScript features and optimizations.

  • ts-helpers:

    ts-helpers is compatible with TypeScript projects that do not require extensive use of advanced TypeScript features. It is particularly beneficial for projects targeting older JavaScript environments where performance is a concern.

Performance

  • tslib:

    tslib enhances performance in larger applications by reducing the amount of duplicated code in the output JavaScript. By providing shared implementations of common features, it helps to keep the generated code efficient and maintainable.

  • ts-helpers:

    ts-helpers offers a performance advantage in smaller projects due to its minimalistic approach. It avoids the overhead of larger libraries while still providing essential functionality for TypeScript features.

Use Cases

  • tslib:

    tslib is best suited for larger applications that heavily utilize TypeScript features and require optimized output. It is recommended for projects that need to manage complex TypeScript constructs and want to ensure efficient runtime performance.

  • ts-helpers:

    ts-helpers is ideal for small libraries or applications where you want to keep dependencies to a minimum while still utilizing TypeScript features. It is particularly useful for projects that aim for a lightweight footprint.

How to Choose: tslib vs ts-helpers
  • tslib:

    Choose tslib if you are looking for a more comprehensive solution that provides a set of utility functions for TypeScript's emitted output. It is ideal for larger projects or applications where you want to ensure that the generated code is optimized for performance and maintainability, especially when using features like async/await or decorators.

  • ts-helpers:

    Choose ts-helpers if you are working on a project that requires minimal runtime overhead and you want to use TypeScript features that require helper functions without adding a large dependency. It is particularly useful for smaller projects or libraries where you want to keep the bundle size low.

README for tslib

tslib

This is a runtime library for TypeScript that contains all of the TypeScript helper functions.

This library is primarily used by the --importHelpers flag in TypeScript. When using --importHelpers, a module that uses helper functions like __extends and __assign in the following emitted file:

var __assign = (this && this.__assign) || Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
        s = arguments[i];
        for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
            t[p] = s[p];
    }
    return t;
};
exports.x = {};
exports.y = __assign({}, exports.x);

will instead be emitted as something like the following:

var tslib_1 = require("tslib");
exports.x = {};
exports.y = tslib_1.__assign({}, exports.x);

Because this can avoid duplicate declarations of things like __extends, __assign, etc., this means delivering users smaller files on average, as well as less runtime overhead. For optimized bundles with TypeScript, you should absolutely consider using tslib and --importHelpers.

Installing

For the latest stable version, run:

npm

# TypeScript 3.9.2 or later
npm install tslib

# TypeScript 3.8.4 or earlier
npm install tslib@^1

# TypeScript 2.3.2 or earlier
npm install tslib@1.6.1

yarn

# TypeScript 3.9.2 or later
yarn add tslib

# TypeScript 3.8.4 or earlier
yarn add tslib@^1

# TypeScript 2.3.2 or earlier
yarn add tslib@1.6.1

bower

# TypeScript 3.9.2 or later
bower install tslib

# TypeScript 3.8.4 or earlier
bower install tslib@^1

# TypeScript 2.3.2 or earlier
bower install tslib@1.6.1

JSPM

# TypeScript 3.9.2 or later
jspm install tslib

# TypeScript 3.8.4 or earlier
jspm install tslib@^1

# TypeScript 2.3.2 or earlier
jspm install tslib@1.6.1

Usage

Set the importHelpers compiler option on the command line:

tsc --importHelpers file.ts

or in your tsconfig.json:

{
    "compilerOptions": {
        "importHelpers": true
    }
}

For bower and JSPM users

You will need to add a paths mapping for tslib, e.g. For Bower users:

{
    "compilerOptions": {
        "module": "amd",
        "importHelpers": true,
        "baseUrl": "./",
        "paths": {
            "tslib" : ["bower_components/tslib/tslib.d.ts"]
        }
    }
}

For JSPM users:

{
    "compilerOptions": {
        "module": "system",
        "importHelpers": true,
        "baseUrl": "./",
        "paths": {
            "tslib" : ["jspm_packages/npm/tslib@2.x.y/tslib.d.ts"]
        }
    }
}

Deployment

  • Choose your new version number
  • Set it in package.json and bower.json
  • Create a tag: git tag [version]
  • Push the tag: git push --tags
  • Create a release in GitHub
  • Run the publish to npm workflow

Done.

Contribute

There are many ways to contribute to TypeScript.

Documentation