UNPKG

3.45 kBMarkdownView Raw
1# tslib
2
3This is a runtime library for [TypeScript](http://www.typescriptlang.org/) that contains all of the TypeScript helper functions.
4
5This library is primarily used by the `--importHelpers` flag in TypeScript.
6When using `--importHelpers`, a module that uses helper functions like `__extends` and `__assign` in the following emitted file:
7
8```ts
9var __assign = (this && this.__assign) || Object.assign || function(t) {
10 for (var s, i = 1, n = arguments.length; i < n; i++) {
11 s = arguments[i];
12 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
13 t[p] = s[p];
14 }
15 return t;
16};
17exports.x = {};
18exports.y = __assign({}, exports.x);
19
20```
21
22will instead be emitted as something like the following:
23
24```ts
25var tslib_1 = require("tslib");
26exports.x = {};
27exports.y = tslib_1.__assign({}, exports.x);
28```
29
30Because 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.
31For optimized bundles with TypeScript, you should absolutely consider using `tslib` and `--importHelpers`.
32
33# Installing
34
35For the latest stable version, run:
36
37## npm
38
39```sh
40# TypeScript 2.3.3 or later
41npm install --save tslib
42
43# TypeScript 2.3.2 or earlier
44npm install --save tslib@1.6.1
45```
46
47## yarn
48
49```sh
50# TypeScript 2.3.3 or later
51yarn add tslib
52
53# TypeScript 2.3.2 or earlier
54yarn add tslib@1.6.1
55```
56
57## bower
58
59```sh
60# TypeScript 2.3.3 or later
61bower install tslib
62
63# TypeScript 2.3.2 or earlier
64bower install tslib@1.6.1
65```
66
67## JSPM
68
69```sh
70# TypeScript 2.3.3 or later
71jspm install tslib
72
73# TypeScript 2.3.2 or earlier
74jspm install tslib@1.6.1
75```
76
77# Usage
78
79Set the `importHelpers` compiler option on the command line:
80
81```
82tsc --importHelpers file.ts
83```
84
85or in your tsconfig.json:
86
87```json
88{
89 "compilerOptions": {
90 "importHelpers": true
91 }
92}
93```
94
95#### For bower and JSPM users
96
97You will need to add a `paths` mapping for `tslib`, e.g. For Bower users:
98
99```json
100{
101 "compilerOptions": {
102 "module": "amd",
103 "importHelpers": true,
104 "baseUrl": "./",
105 "paths": {
106 "tslib" : ["bower_components/tslib/tslib.d.ts"]
107 }
108 }
109}
110```
111
112For JSPM users:
113
114```json
115{
116 "compilerOptions": {
117 "module": "system",
118 "importHelpers": true,
119 "baseUrl": "./",
120 "paths": {
121 "tslib" : ["jspm_packages/npm/tslib@1.13.0/tslib.d.ts"]
122 }
123 }
124}
125```
126
127
128# Contribute
129
130There are many ways to [contribute](https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md) to TypeScript.
131
132* [Submit bugs](https://github.com/Microsoft/TypeScript/issues) and help us verify fixes as they are checked in.
133* Review the [source code changes](https://github.com/Microsoft/TypeScript/pulls).
134* Engage with other TypeScript users and developers on [StackOverflow](http://stackoverflow.com/questions/tagged/typescript).
135* Join the [#typescript](http://twitter.com/#!/search/realtime/%23typescript) discussion on Twitter.
136* [Contribute bug fixes](https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md).
137
138# Documentation
139
140* [Quick tutorial](http://www.typescriptlang.org/Tutorial)
141* [Programming handbook](http://www.typescriptlang.org/Handbook)
142* [Homepage](http://www.typescriptlang.org/)