-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Declarations and "Exported variable 'XXX' has or is using name 'YYY' from external module "ZZZ" but cannot be named." #24666
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
Comments
I can't find the comment I made on a workaround anymore. It was on a similar issue but even worse, because when this happens with generic types, you generally find yourself losing out on type inference. The workaround was to use the imported type with a dummy variable if it's an interface or type alias. If it's a class, you can get away with With interfaces and the like, import {SomeGenericInterface} from "thing";
const dummy : SomeGenericInterface<any, any, any>|undefined = undefined;
dummy; I'm on my phone so I'm not sure if I've described it properly. This way, type inference still works and you've imported and used the type. but it's extremely ugly and hacky. And, in general, you don't know what needs to be imported and used this way until you want to compile the code... I wish there was a way for it to automatically import during the compile phase because this workaround I use has given me no problems. It's just repeatedly,
So, I've got it down to an algorithm but you might end up needing to do this for hundreds of files, to compile. And you don't need to do this at all with |
Thanks, @AnyhowStep - that's very similar to what I do at the moment too: ((_1?: StyledComponentClass<any, any>, _2?: typeof React) => 0)(); 🤢 I've got dozens of files that start this way. |
I like your way better, actually. |
I just tried something and it seemed to work (I haven't exhaustively tested this so I'm not 100% sure) Just do, import * as package1 from "some-package-1";
import * as package2 from "some-package-2";
package1;
package2; Assuming Doesn't help so much if you only need the one type. |
@jamiewinder Thanks for the report! Apologies - looks like our visibility checking logic in declaration emit didn't handle things aliased via |
I was pleased to see #9944 had been closed with what looked like a feature of 2.9 'fixing' the issue. However, it still doesn't seem to be working as I'd expect. Take this example:
With a normal TypeScript project, using the tsconfig default except enabling
declarations
. I get three errors:The obvious solution seems to be importing the types involved:
Which would be fine, I suppose (though I don't see why it is necessary..?) but this doesn't work with
noUnusedLocals
as you get more errors:... However you can work around that by explicitly using the types, but even with this basic example it gets absurdly verbose:
What is the recommended solution / workaround to this?
The text was updated successfully, but these errors were encountered: