1
|
# tslib
|
2
|
|
3
|
This is a runtime library for [TypeScript](http://www.typescriptlang.org/) that contains all of the TypeScript helper functions.
|
4
|
|
5
|
This library is primarily used by the `--importHelpers` flag in TypeScript.
|
6
|
When using `--importHelpers`, a module that uses helper functions like `__extends` and `__assign` in the following emitted file:
|
7
|
|
8
|
```ts
|
9
|
var __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
|
};
|
17
|
exports.x = {};
|
18
|
exports.y = __assign({}, exports.x);
|
19
|
|
20
|
```
|
21
|
|
22
|
will instead be emitted as something like the following:
|
23
|
|
24
|
```ts
|
25
|
var tslib_1 = require("tslib");
|
26
|
exports.x = {};
|
27
|
exports.y = tslib_1.__assign({}, exports.x);
|
28
|
```
|
29
|
|
30
|
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.
|
31
|
For optimized bundles with TypeScript, you should absolutely consider using `tslib` and `--importHelpers`.
|
32
|
|
33
|
# Installing
|
34
|
|
35
|
For the latest stable version, run:
|
36
|
|
37
|
## npm
|
38
|
|
39
|
```sh
|
40
|
# TypeScript 2.3.3 or later
|
41
|
npm install --save tslib
|
42
|
|
43
|
# TypeScript 2.3.2 or earlier
|
44
|
npm install --save tslib@1.6.1
|
45
|
```
|
46
|
|
47
|
## yarn
|
48
|
|
49
|
```sh
|
50
|
# TypeScript 2.3.3 or later
|
51
|
yarn add tslib
|
52
|
|
53
|
# TypeScript 2.3.2 or earlier
|
54
|
yarn add tslib@1.6.1
|
55
|
```
|
56
|
|
57
|
## bower
|
58
|
|
59
|
```sh
|
60
|
# TypeScript 2.3.3 or later
|
61
|
bower install tslib
|
62
|
|
63
|
# TypeScript 2.3.2 or earlier
|
64
|
bower install tslib@1.6.1
|
65
|
```
|
66
|
|
67
|
## JSPM
|
68
|
|
69
|
```sh
|
70
|
# TypeScript 2.3.3 or later
|
71
|
jspm install tslib
|
72
|
|
73
|
# TypeScript 2.3.2 or earlier
|
74
|
jspm install tslib@1.6.1
|
75
|
```
|
76
|
|
77
|
# Usage
|
78
|
|
79
|
Set the `importHelpers` compiler option on the command line:
|
80
|
|
81
|
```
|
82
|
tsc --importHelpers file.ts
|
83
|
```
|
84
|
|
85
|
or in your tsconfig.json:
|
86
|
|
87
|
```json
|
88
|
{
|
89
|
"compilerOptions": {
|
90
|
"importHelpers": true
|
91
|
}
|
92
|
}
|
93
|
```
|
94
|
|
95
|
#### For bower and JSPM users
|
96
|
|
97
|
You 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
|
|
112
|
For 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.11.1/tslib.d.ts"]
|
122
|
}
|
123
|
}
|
124
|
}
|
125
|
```
|
126
|
|
127
|
|
128
|
# Contribute
|
129
|
|
130
|
There 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
|
* Read the language specification ([docx](http://go.microsoft.com/fwlink/?LinkId=267121), [pdf](http://go.microsoft.com/fwlink/?LinkId=267238)).
|
138
|
|
139
|
# Documentation
|
140
|
|
141
|
* [Quick tutorial](http://www.typescriptlang.org/Tutorial)
|
142
|
* [Programming handbook](http://www.typescriptlang.org/Handbook)
|
143
|
* [Language specification](https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md)
|
144
|
* [Homepage](http://www.typescriptlang.org/)
|