Skip to content

Circular references with TS 1.1.0-1 and 1.3 when loading file from another directory #1107

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

Closed
Vadorequest opened this issue Nov 9, 2014 · 4 comments
Labels
Bug A bug in TypeScript Duplicate An existing issue was already created

Comments

@Vadorequest
Copy link

Hi.

I have updated my typescript (npm install typescript -g) recently and now I have an issue with some multiple references to the same file.

It worked fine under TS 1.0.

shared/app/Sails.ts:

///<reference path='./lib/def/defLoader.d.ts'/>

import cli = require('./../../shared/app/Cli');
var Cli = cli.Cli;

export class Sails{

}

Because Cli also imports the same defLoader.d.ts, I get the following errors:

../../shared/app/lib/def/JQuery.d.ts(23,5): error TS2300: Duplicate identifier 'accepts'.
../../shared/app/lib/def/JQuery.d.ts(24,5): error TS2300: Duplicate identifier 'async'.
../../shared/app/lib/def/JQuery.d.ts(26,5): error TS2300: Duplicate identifier 'cache'.
../../shared/app/lib/def/JQuery.d.ts(28,5): error TS2300: Duplicate identifier 'contents'.
../../shared/app/lib/def/JQuery.d.ts(31,5): error TS2300: Duplicate identifier 'contentType'.
../../shared/app/lib/def/JQuery.d.ts(32,5): error TS2300: Duplicate identifier 'context'.

(much more errors but I guess you get what's the issue)

I can solve it two ways, either by removing the Cli reference (so, I don't require the file), or by removing the //<reference path at the top of the file.

I didn't have this problem in TS 1.0.

Weird thing, I have this issue only here, even if in some other files I do the same, I don't get the error there and I'm not able to understand why it works there while here it fails.

But I just figured it out while writing this issue. It is because of the path used to load my Cli module, I used require('./../../shared/app/Cli'); while I should have used require('./Cli'); and because of this somehow the compiler tried to perform the reference twice because it thought it was another file. Well, I didn't have this issue in TS 1.0, I don't know if it's on purpose, anyway my issue is solved now, just wanted to give you a feedback.

Keep up the good work, looking forward for TS 2.0!

@mhegazy
Copy link
Contributor

mhegazy commented Nov 10, 2014

@Vadorequest I could not piece together a repro form your description above. just including defLoader.d.ts from Sails and Cli does not seem to do the trick. can you share more details.

@mhegazy mhegazy added the Needs More Info The issue still hasn't been fully clarified label Nov 10, 2014
@Vadorequest
Copy link
Author

I have just made a github project so you can test it with a use case.

https://github.com/Vadorequest/TS-issue-1107

@mhegazy mhegazy added the Bug A bug in TypeScript label Nov 10, 2014
@mhegazy
Copy link
Contributor

mhegazy commented Nov 10, 2014

i think this is the same issue as #1039. If you start with relative paths, the compiler will not attempt to resolve them to absolute path, that means that you can have the same file with multiple different path, and then it will be included multiple times. i have listed a few workarounds in #1039.

@mhegazy mhegazy added Duplicate An existing issue was already created and removed Needs More Info The issue still hasn't been fully clarified labels Nov 10, 2014
@Vadorequest
Copy link
Author

It looks like it is related indeed :)
I have fixed it in my application, thanks for workaround.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants