Skip to content

Typescript 3.9 CommonJS code emitted sets exports to void 0 (leading to error TS2323: Cannot redeclare exported variable) #38552

Closed
@lineape

Description

@lineape

TypeScript Version: 3.9.2

Search Terms:
TS2323: Cannot redeclare exported variable, CommonJS, exports

Code

export const export1 = '';
export const export2 = '';

Expected behavior:

in TypeScript 3.8.x, with --module CommonJS

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.export1 = '';
exports.export2 = '';

https://www.typescriptlang.org/play/?module=1&ts=3.8.3#code/KYDwDg9gTgLgBAYwgOwM71JWBGOBeOAckIG4AoTaeJNDcKgJnyNLKA

Actual behavior:

in TypeScript 3.9.2, with --module CommonJS

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.export2 = exports.export1 = void 0;
exports.export1 = '';
exports.export2 = '';

Playground Link:
https://www.typescriptlang.org/play/?module=1&ts=3.9.2#code/KYDwDg9gTgLgBAYwgOwM71JWBGOBeOAckIG4AoTaeJNDcKgJnyNLKA

This is a regression because the code emitted leads to compiler errors when imported by javascript when --checkJs is true

error TS2323: Cannot redeclare exported variable 'export1'
error TS2323: Cannot redeclare exported variable 'export2'

I've worked around this by setting --declaration to true and excluding the javascript, but there doesn't seem to be a reason why this change was made.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issuecheckJsRelates to checking JavaScript using TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions