-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jonas Bandi
committed
Oct 1, 2016
1 parent
3c4e916
commit 69b4bac
Showing
12 changed files
with
137 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,22 @@ | ||
# ts-superset-myth | ||
Experimenting with ES2015 -> TypeScript compatibility | ||
|
||
To get started: | ||
|
||
npm install | ||
|
||
|
||
To compile the TypeScript: | ||
|
||
npm run compile | ||
|
||
To load the examples in the browser: | ||
|
||
npm start | ||
|
||
Then browse to `http://localhost:7005/` | ||
|
||
|
||
This example throws compilation errors even though the code is valid ES2016. | ||
|
||
Go to the branch `es2015` to see exactly the same code running with Babel/Webpack. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {first, second, third} from './my-lib' | ||
import Car from './car'; | ||
import {calculate} from './calculate' | ||
|
||
// Dynamically added properties are not valid in TypeScript | ||
console.log(first.name); | ||
console.log(second.organization); | ||
|
||
|
||
// TS does not support all cases of ES2015 destructuring | ||
const {name = 'John Doe', organization = 'Project Mayhem', message = 'Do not talk about superset!'} = third; // TS does not allow destructuring an obj to optional variables ... | ||
|
||
function doSomething({name = 'John Doe', organization = 'Project Mayhem', message = 'Do not talk about superset!'}){} // ... but it is valid to destructuring an object to optional function arguments ?!? | ||
doSomething(third); | ||
|
||
|
||
// ES2015 classes are not valid TypeScript classes | ||
const myCar = new Car(42); | ||
console.log(myCar.weight); | ||
|
||
// ES2015 modules (as WebPack understands them), are not valid TypeScript modules | ||
const result = calculate([1,2,3]); | ||
console.log(result); | ||
|
||
console.log('Hello from TypeScript!'); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import map from 'lodash/map'; | ||
// import {map} from 'lodash'; | ||
|
||
export function calculate(input: Array<number>){ | ||
return map(input, n => n + 3); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default class Car { | ||
constructor(private weight) { | ||
this.weight = weight; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const first = {}; | ||
|
||
first.name = 'Tyler Durden'; | ||
|
||
// | ||
const prop = 'organization'; | ||
const second = { | ||
name: 'Tyler Durden', | ||
[prop]: 'Fight Club' | ||
}; | ||
|
||
const third = { | ||
name: 'Tyler Durden', | ||
organization: 'Fight Club' | ||
}; | ||
|
||
|
||
export {first, second, third} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es5", | ||
"sourceMap": true, | ||
"allowJs": true, | ||
"outDir": "build" | ||
}, | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters