-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
TS4023: Exported variable 'X' has or is using name 'Y' from external module 'a/file/path' but cannot be named #5711
Comments
Oh - if this isn't a suitable place to ask this question. Please let me know and I'd be happy to post it on another medium. |
FWIW you'll usually get faster answers on Stack Overflow, but we do field well-phrased questions here. The problem here is that you're using the When trying to emit If you add an |
Hi Ryan - thanks for the advice RE stack overflow and the advice - adding the import to A little context here - my goal here is indeed to generate declarations for my external modules. (Something I believe isn't quite working yet? #5039?) This import may be completely necessary but It feels a little strange for
Or via
I know very little about the TS compiler - so maybe what I'm saying is completely unrealistic, but at first thought it feels like the compiler could deduce that Thank you again for taking the time to answer. I've sorted my problem now so the above is mainly curiosity - there's no rush to answer. |
I'm not sure exactly what you're saying. What should |
The compiler will not add dependencies (i.e. import statements) that did not exist in the user code when it emits declarations. the error you are getting means that the compiler is trying to write a type annotation for an exported declaration but could not. this can have one of two reasons, either the name is not accessible, i.e. not imported in the current module, or there is a declaration that is shadowing the original declaration. in both cases, your work around is to add explicit type annotation, if you add any type annotation, it will be emitted verbatim in the output; the other option is to make sure the name is accessible, i.e. you have an import to the module, and you understand what that means for your users that are importing your module. |
This lead to error TS4023 when a type if needed to describe something that has not been imported to the module. See also microsoft/TypeScript#5711 (comment)
@mhegazy said:
The problem is that I don't always need the import statements in the code (obviously, since it works without |
feel free to log an issue to track this suggestion. the rational was imports are a declaration of dependency, and the compiler should not create one for you unless you instruct it to do. |
This could have deeper consequences. Consider
When This means either:
If
EDIT: I am able to reproduce it and indeed my
|
I have the same problem described by @unional |
Please reopen this issue, the issues outlined by @unional are very realistic and this makes it very hard to add any intermediate/helper libs on top of libraries while using the same types as the original module we are re-exporting. |
Issue #9944 tracks adding the import at the declaration emit phase. |
Thank! |
as described here: microsoft/TypeScript#5711
The problem with adding the import is that with class Whatever {
fetch(uri: string): Promise<void> { }
ensureFetched = MemoizedFunction<(uri: string) => Promise<void>> = memoize((uri: string) => this.fetch(uri))
} I would like to omit type annotation for |
I found a workaround for this: |
@salim7 this slows down your compilation times (because you're recompiling a library that should've already been compiled) and forces you to use the least common denominator of strictness settings with the target library. |
@mhegazy the problem has reproduced in next scenario:
Solution is specify type explicit:
|
I can not get this to reproduce using the sample above. please file a new bug, and provide more context to be able to reproduce the issue. |
@PFight Thank you! That was it for me! |
I have just faced this issue when using: export { IMyInterface } from './file' The solution was to do this: import { IMyInterface } from './file'
export { IMyInterface } But this really shouldn't be necessary tbh. |
Did anyone figured out how to deal with |
@yordis |
@pelotom yeah this is completely my fault, I was thinking on one thing and I wrote something else. Did Typescript fixed the issue between |
My current workaround, which feels like a total pain to me,
Avoids |
* Re-type `helper` from @ember/component/helper Previous typing caused an error about using private name `Ember.Helper` when generating declaration files. Fortunately, the previous typings were incorrect anyway, so we can remove the reference to `Ember.Helper` and thus fix the issue. Relevant links: * microsoft/TypeScript#5711 * microsoft/TypeScript#6307 * https://www.emberjs.com/api/ember/2.18/functions/@ember%2Fcomponent%2Fhelper/helper * https://github.com/emberjs/ember.js/blob/v2.18.2/packages/ember-glimmer/lib/helper.ts#L120 * Add test for `helper` from @ember/component/helper
I'm attempting to create a set of external TypeScript modules as follows:
The idea is that this will be compiled down and supplied as a library. The plan is that the consumer of the library will instantiate an instance of ClassA as follows:
This looks as though it is compiling down to the expected JS, but I'm getting an error compiler error which I'm struggling to find further information about.
Can anyone here shed any light on this issue? Does what I'm trying to do make sense?
The text was updated successfully, but these errors were encountered: