Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit b0a6608

Browse files
committed
add intro
1 parent e3af3df commit b0a6608

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

public/docs/_examples/cb-ts-to-js/js-es6-decorators/.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"es2015",
44
"angular2"
55
]
6-
}
6+
}

public/docs/js/latest/cookbook/ts-to-js.jade

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ include ../../../../_includes/_util-fns
1616
:marked
1717
## Table of contents
1818

19+
[From TS to ES6 to ES5](#from-ts)
20+
1921
[Modularity: imports and exports](#modularity)
2022

2123
[Classes and Class Metadata](#class-metadata)
@@ -29,6 +31,35 @@ include ../../../../_includes/_util-fns
2931
**Run and compare the live <live-example name="cb-ts-to-js">TypeScript</live-example> and <live-example name="cb-ts-to-js" lang="js">JavaScript</live-example>
3032
code shown in this cookbook.**
3133

34+
a(id="from-ts")
35+
.l-main-section
36+
:marked
37+
## From TS to ES6 to ES5
38+
39+
Since TypeScript is a superset of ES6 Javascript, and ES6 itself is a superset of ES5, the
40+
transformation of Typescript code all the way to ES5 javascript can be seen as "shedding"
41+
features.
42+
43+
When going from TypeScript to ES6 with decorators, we mostly remove
44+
[type annotations](https://www.typescriptlang.org/docs/handbook/basic-types.html)
45+
, such as `string` or `boolean`, and
46+
[class property modifiers](http://www.typescriptlang.org/docs/handbook/classes.html#public-private-and-protected-modifiers)
47+
such as `public` and `private`.
48+
The exception is type annotations used for dependency injection, which can be kept.
49+
50+
Going from ES6 with decorators to plan ES6 Javascript we lose all
51+
[decorators](https://www.typescriptlang.org/docs/handbook/decorators.html)
52+
the remaining type annotations.
53+
We also lose class properties, which now have to be declared in the class constructor.
54+
55+
Finally, in the transition from ES6 to ES5 Javascript the main missing features are `import`
56+
statements and `class` declarations.
57+
58+
For ES6 transpilation we recommend using a similar setup as our TypeScript quickstart,
59+
replacing TypeScript with [Babel](https://babeljs.io/) using the `es2015` preset.
60+
To use decorators and annotations with Babel, install the
61+
[`angular2`](https://github.com/shuhei/babel-plugin-angular2-annotations) preset as well.
62+
3263
a(id="modularity")
3364
.l-main-section
3465
:marked

0 commit comments

Comments
 (0)