Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot redefine exports when exporting identifiers with the same name from different files #38530

Closed
leon19 opened this issue May 13, 2020 · 1 comment · Fixed by #38809
Closed
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@leon19
Copy link

leon19 commented May 13, 2020

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 from module.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

@leon19 leon19 changed the title Cannot redefine exports when exporting identifiers with the same name in different files Cannot redefine exports when exporting identifiers with the same name from different files May 13, 2020
yvann added a commit to prismamedia/graphql-platform that referenced this issue May 15, 2020
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label May 26, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.0 milestone May 26, 2020
@weswigham weswigham added Bug A bug in TypeScript Fix Available A PR has been opened for this issue and removed Needs Investigation This issue needs a team member to investigate its status. labels May 27, 2020
yvann added a commit to prismamedia/graphql-platform that referenced this issue Jun 4, 2020
@ValentinH
Copy link

Did someone find a workaround, except downgrading to 3.8?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants