Description
I've updated to version 3.9.2 and now it's no longer possible to redefine exports. I'm not sure if it is the expected behaviour from now on since it was introduced as a feature (#35967)
TypeScript Version: 3.9.2
Search Terms:
- Cannot redefine property
Code
Let's suppose I've the following files
- module.ts:
export const isOne = (input: any) => input == 1;
export const isTwo = (input: any) => input === 2;
-
fixed-module.ts
In this files I've fixed some extrange behaviour from
module.ts
export const isOne = (input: any) => input === 1;
-
modified-module.ts
In this file I export the whole
module.ts
alongside the fixes I've been applied in order to have the imports frommodule.ts
in a single file
export * from "./module";
export { isOne } from "./fixed-module";
-
index.ts
This file represents my app
import { isOne } from "./modified-module";
Later on, when I want to to run my app:
npx tsc --init
npx tsc
node index.js
Object.defineProperty(exports, "isOne", { enumerable: true, get: function () { return fixed_module_1.isOne; } });
^
TypeError: Cannot redefine property: isOne
at Function.defineProperty (<anonymous>)
at Object.<anonymous> (/tmp/test/modified-module.js:15:8)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
at Module.load (internal/modules/cjs/loader.js:1002:32)
at Function.Module._load (internal/modules/cjs/loader.js:901:14)
at Module.require (internal/modules/cjs/loader.js:1044:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object.<anonymous> (/tmp/test/index.js:3:25)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
Bonus:
It actually works if I redefine the export in the same file:
- modified-module.ts
export * from "./module";
export const isOne = (input: any) => input === 1;
Expected behavior:
I should be allowed to redefine exports
Actual behavior:
The export cannot be redefined and it throws an error
Related Issues: #35967