Description
openedon Jan 2, 2016
The import/export statements used in ES6 modules allow tools such as Webpack and Rollup.js to eliminate all the code from unused exports. (For example, see Dr. Axel Rauschmayer's post on this topic)
However, targeting ES5 remove the import/export statements, so these tools cannot remove unused exports.
TypeScript 1.7 included 'es6' and 'es2015' as valid options for the 'module' setting, but the following config:
// tsconfig.json
{
"compilerOptions": {
"module": "es6",
"target": "es5"
}
}
Produces this error:
error TS1204: Cannot compile modules into 'es6' when targeting 'ES5' or lower.
So, it looks like it is not currently possible to generate ES5 code while retaining the import/export statements of ES6 modules.
This is related to issue #4692 that proposes enabling more granular targeting beyond 'ES5' or 'ES6', but in this particular case the two required options already exist in tsconfig.json ('target' and 'module'), but the particular combination of values ('target':'es5', 'module':'es6') doesn't work.