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 be named” when generating declarations for re-exported classes #8612

Closed
dakisxx opened this issue May 15, 2016 · 3 comments · Fixed by #19852
Closed

“cannot be named” when generating declarations for re-exported classes #8612

dakisxx opened this issue May 15, 2016 · 3 comments · Fixed by #19852
Labels
Duplicate An existing issue was already created

Comments

@dakisxx
Copy link

dakisxx commented May 15, 2016

TypeScript Version:

1.8.10 / nightly (1.9.0-dev.20160515)

Code

// file ThingA.ts
export class ThingA { } 

// file ThingB.ts
export class ThingB { }

// file Things.ts (re-export)
export {ThingA} from "./ThingA";
export {ThingB} from "./ThingB";

// file Test.ts (uses re-exported classes)
import * as things from "./Things";

export class Test {
    public method = (input: things.ThingA)  => { };
}

// compile
tsc Test.ts --declaration --outDir compiled

Expected behavior:
No errors
Actual behavior:

Test.ts(5,5): error TS4029: Public property 'method' of exported class has or is using name 'ThingA' from external module ".../ThingA" but cannot be named.

It seems declaration file can't be generated due to the things.ThingA reference, but in a similar case without re-exporting it works fine (I will give an example of this in the next post).

If I change the import statement in Test.ts to this:

import {ThingA,ThingB} from "./Things";

(instead of import * as things) and further use ThingA directly, there are no errors, but this defeats the purpose of re-exporting.

@dakisxx
Copy link
Author

dakisxx commented May 15, 2016

Here is a similar example without a re-export which works fine:

// file Things.ts
export class ThingA { } 
export class ThingB { }

// file Test.ts
import * as things from "./Things";

export class Test {
    public method = (input: things.ThingA)  => { };
}

// compile
tsc Test.ts --declaration --outDir compiled

This is the generated Test.d.ts

import * as things from "./Things";
export declare class Test {
    method: (input: things.ThingA) => void;
}

@mhegazy
Copy link
Contributor

mhegazy commented May 16, 2016

this is the same root cause as #5938. the compiler follows the export * references to their sources, then it does not find this file explicitly imported and and thus thinks that the name is not available on any of the imports.

@mhegazy mhegazy closed this as completed May 16, 2016
@mhegazy mhegazy added the Duplicate An existing issue was already created label May 16, 2016
@mhegazy
Copy link
Contributor

mhegazy commented May 16, 2016

closing in favor of #5938

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

Successfully merging a pull request may close this issue.

2 participants