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

"duplicate identifier" error in js files produced by tsc #7077

Closed
d180cf opened this issue Feb 14, 2016 · 8 comments
Closed

"duplicate identifier" error in js files produced by tsc #7077

d180cf opened this issue Feb 14, 2016 · 8 comments
Labels
Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@d180cf
Copy link

d180cf commented Feb 14, 2016

Let's say we have the following ts file:

function abc() {
  // ...
}

module abc {
  export const def = 123;
}

tsc converts this into the following js file:

function abc() {
  // ...
}

var abc;
abc.def = 123; // well, there is actually a function (abc) { ... } wrapper here

Now if I try to include this js file into another ts file, tsc will scan the js file it's just generated and will report an error: "duplicate identifier abc". Once the "var abc" part is removed, the error goes away. Tried with the latest typescript@next (which was 1.9.0-dev.20160214).

The good news is that this is the only error I'm getting from a exceptionally sophisticated js file.

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Feb 16, 2016
@RyanCavanaugh
Copy link
Member

We could do the work to not emit the var when we know we've already emitted the function. Note that this isn't going to solve every case since you might have these declarations in separate files.

@d180cf
Copy link
Author

d180cf commented Feb 16, 2016

I'm actually thinking that emitting the error isn't correct in this case: an empty "var" should be a noop if the var was already declared.

@mhegazy
Copy link
Contributor

mhegazy commented Feb 16, 2016

@d180cf as per the JS semantics, the additional var is a no-op. the typescript compiler imposes a bit stricter semantics here; the assumption here is that you did that be mistake and you did not mean to re-declare the variable, and that might point you to an actual bug, either related to scoping or incorrect use.
I agree with @RyanCavanaugh that the compiler output should hold up to its own check.

@basarat
Copy link
Contributor

basarat commented Feb 17, 2016

If one uses outDir and exclude options wouldn't this be avoided altogether 🌹

@mhegazy mhegazy added Help Wanted You can do this and removed In Discussion Not yet reached consensus labels Mar 8, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Mar 8, 2016

PRs welcomed!

@mhegazy mhegazy added this to the Community milestone Mar 8, 2016
@RyanCavanaugh RyanCavanaugh added the Good First Issue Well scoped, documented and has the green light label Mar 8, 2016
@RyanCavanaugh
Copy link
Member

@mhegazy we should probably hold off on PRs for this until after the tree transforms work comes in? Don't want to solicit throwaway work

@RyanCavanaugh RyanCavanaugh removed the Good First Issue Well scoped, documented and has the green light label Mar 8, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Mar 8, 2016

that is correct. here is the issue to look out for: #5595

@RyanCavanaugh RyanCavanaugh modified the milestones: Community, Backlog Mar 7, 2019
@RyanCavanaugh
Copy link
Member

This is fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants