Skip to content

Support 'target':'es5' with 'module':'es6' to allow dead code elimination #6319

Closed

Description

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

CommittedThe team has roadmapped this issueFixedA PR has been merged for this issueSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions