Reputation: 42613
In Typescript 1.7 a feature was added that allows to separately target language system and module system, ex it can produce ES6 code with CommonJS module system for latest node. But if I try it with following command and source code:
tsc *.ts --target es6 --module commonjs
// foo.ts
"use strict";
import Bar from './bar';
console.log(Bar);
// bar.ts
"use strict";
export default class Bar {}
Surprisingly, resulting code have some very strange export notation being generated:
// foo.js
"use strict";
var bar_1 = require('./bar');
console.log(bar_1.default);
// bar.js
"use strict";
class Bar {}
exports.Bar = Bar;
As you can see, bar.js
results in being exporting Bar
object, while foo.js
attempts to import default
object. And of course this code displays "undefined" being imported if executed via latest nodejs
v4.1.0
Any hints why such strange behaviour?
Upvotes: 2
Views: 794
Reputation: 28686
You found a bug in TS 1.7. I believe this is the correct issue:
I verified it by running the code in TS@next (Version 1.8.0-dev.20151216):
npm install typescript@next --save
node node_modules/typescript/bin/tsc --target es6 --module commonjs *.ts && node foo.js
Upvotes: 2