Skip to content

Commit 8002684

Browse files
fathybdevongovett
authored andcommitted
Set TypeScript option esModuleInterop to true by default (#971)
1 parent e3c90c4 commit 8002684

6 files changed

Lines changed: 31 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"sinon": "^4.2.2",
8989
"sourcemap-validator": "^1.0.6",
9090
"stylus": "^0.54.5",
91-
"typescript": "^2.6.2"
91+
"typescript": "^2.7.0"
9292
},
9393
"scripts": {
9494
"test": "cross-env NODE_ENV=test mocha",

src/assets/TypeScriptAsset.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ class TypeScriptAsset extends JSAsset {
88
let transpilerOptions = {
99
compilerOptions: {
1010
module: typescript.ModuleKind.CommonJS,
11-
jsx: typescript.JsxEmit.Preserve
11+
jsx: typescript.JsxEmit.Preserve,
12+
13+
// it brings the generated output from TypeScript closer to that generated by Babel
14+
// see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html
15+
esModuleInterop: true
1216
},
1317
fileName: this.relativeName
1418
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = () => 'test passed'
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import testModule from './commonjs-module'
2+
3+
export const test = testModule

test/typescript.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,24 @@ describe('typescript', function() {
106106
let file = fs.readFileSync(__dirname + '/dist/index.js', 'utf8');
107107
assert(file.includes('React.createElement("div"'));
108108
});
109+
110+
it('should use esModuleInterop by default', async function() {
111+
let b = await bundle(
112+
__dirname + '/integration/typescript-interop/index.ts'
113+
);
114+
115+
assertBundleTree(b, {
116+
name: 'index.js',
117+
assets: ['index.ts', 'commonjs-module.js'],
118+
childBundles: [
119+
{
120+
type: 'map'
121+
}
122+
]
123+
});
124+
125+
let output = run(b);
126+
assert.equal(typeof output.test, 'function');
127+
assert.equal(output.test(), 'test passed');
128+
});
109129
});

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6087,7 +6087,7 @@ typedarray@^0.0.6:
60876087
version "0.0.6"
60886088
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
60896089

6090-
typescript@^2.6.2:
6090+
typescript@^2.7.0:
60916091
version "2.7.2"
60926092
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.7.2.tgz#2d615a1ef4aee4f574425cdff7026edf81919836"
60936093

0 commit comments

Comments
 (0)