Debian Codegraph @

node/tslib/README.md

raw
1 # tslib
2
3 This is a runtime library for [TypeScript](https://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 3.9.2 or later
41 npm install tslib
42
43 # TypeScript 3.8.4 or earlier
44 npm install tslib@^1
45
46 # TypeScript 2.3.2 or earlier
47 npm install [email protected]
48 ```
49
50 ## yarn
51
52 ```sh
53 # TypeScript 3.9.2 or later
54 yarn add tslib
55
56 # TypeScript 3.8.4 or earlier
57 yarn add tslib@^1
58
59 # TypeScript 2.3.2 or earlier
60 yarn add [email protected]
61 ```
62
63 ## bower
64
65 ```sh
66 # TypeScript 3.9.2 or later
67 bower install tslib
68
69 # TypeScript 3.8.4 or earlier
70 bower install tslib@^1
71
72 # TypeScript 2.3.2 or earlier
73 bower install [email protected]
74 ```
75
76 ## JSPM
77
78 ```sh
79 # TypeScript 3.9.2 or later
80 jspm install tslib
81
82 # TypeScript 3.8.4 or earlier
83 jspm install tslib@^1
84
85 # TypeScript 2.3.2 or earlier
86 jspm install [email protected]
87 ```
88
89 # Usage
90
91 Set the `importHelpers` compiler option on the command line:
92
93 ```
94 tsc --importHelpers file.ts
95 ```
96
97 or in your tsconfig.json:
98
99 ```json
100 {
101 "compilerOptions": {
102 "importHelpers": true
103 }
104 }
105 ```
106
107 #### For bower and JSPM users
108
109 You will need to add a `paths` mapping for `tslib`, e.g. For Bower users:
110
111 ```json
112 {
113 "compilerOptions": {
114 "module": "amd",
115 "importHelpers": true,
116 "baseUrl": "./",
117 "paths": {
118 "tslib" : ["bower_components/tslib/tslib.d.ts"]
119 }
120 }
121 }
122 ```
123
124 For JSPM users:
125
126 ```json
127 {
128 "compilerOptions": {
129 "module": "system",
130 "importHelpers": true,
131 "baseUrl": "./",
132 "paths": {
133 "tslib" : ["jspm_packages/npm/[email protected]/tslib.d.ts"]
134 }
135 }
136 }
137 ```
138
139 ## Deployment
140
141 - Choose your new version number
142 - Set it in `package.json` and `bower.json`
143 - Create a tag: `git tag [version]`
144 - Push the tag: `git push --tags`
145 - Create a [release in GitHub](https://github.com/microsoft/tslib/releases)
146 - Run the [publish to npm](https://github.com/microsoft/tslib/actions?query=workflow%3A%22Publish+to+NPM%22) workflow
147
148 Done.
149
150 # Contribute
151
152 There are many ways to [contribute](https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md) to TypeScript.
153
154 * [Submit bugs](https://github.com/Microsoft/TypeScript/issues) and help us verify fixes as they are checked in.
155 * Review the [source code changes](https://github.com/Microsoft/TypeScript/pulls).
156 * Engage with other TypeScript users and developers on [StackOverflow](http://stackoverflow.com/questions/tagged/typescript).
157 * Join the [#typescript](http://twitter.com/#!/search/realtime/%23typescript) discussion on Twitter.
158 * [Contribute bug fixes](https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md).
159
160 # Documentation
161
162 * [Quick tutorial](http://www.typescriptlang.org/Tutorial)
163 * [Programming handbook](http://www.typescriptlang.org/Handbook)
164 * [Homepage](http://www.typescriptlang.org/)