You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeSctript does a very good job generating declaration files based on existing JS files, even in complex scenarios.
However, some errors appear when TypeScript decides to import declarations from other files. This happens when referenced declarations are sufficiently large (as in this example) to not be just copied.
In the ./file-b.d.ts generated declaration file I get the following errors in order of appearance (see code):
TS2503: Cannot find namespace 'myTypes'.
TS1147: Import declarations in a namespace cannot reference a module.
TS2307: Cannot find module './file-a.js' or its corresponding type declarations.
When the import statement is moved outside of the namespace, all errors disappear (makes sense from a JS point of view).
Beside this highlighted errors, only seen when opening the generated declaration files. Everything seems to work as intended (Type checking, auto-completion, etc.). Even when consuming the compiled library with the generated declaration files included (with those "errors" present).
Expected behavior:
No error to be present in generated declaration files.
Actual behavior:
Errors are present as explained above.
Playground Link: Not possible because import/export involved.
@RyanCavanaugh@weswigham I've run additional tests and it seems that this issue is causing problems when consuming the generated declaration files. Specifically, typescript won't compile a project if a package with the above faulty declarations is being used.
I would suggest to rise priority for this bug. TypeScript 4 might be too far in the future.
In some scenarios, when there is a name conflict, moving the import statement out of the namespace might not be enough. Maybe import with alias should be used in this cases.
It is strange, because I remember seeing the import with alias strategy in some generated declaration files in the past. It seems that the generation logic is not consistent.
@RyanCavanaugh@weswigham sorry to bother you again. If you point me to the section in your codebase where this logic is defined, I would be glad to fix it myself. Please let me know.
TypeScript Version: 3.9.0-dev.20200324
Search Terms: declaration errors, declaration files, TS1147, TS2307, TS2503
(ISSUE EXPLANATION BELOW)
Code
Source:
./file-a.js
./file-b.js
Generated Declarations:
./file-a.d.ts
./file-b.d.ts
Issue explanation:
TypeSctript does a very good job generating declaration files based on existing JS files, even in complex scenarios.
However, some errors appear when TypeScript decides to import declarations from other files. This happens when referenced declarations are sufficiently large (as in this example) to not be just copied.
In the
./file-b.d.ts
generated declaration file I get the following errors in order of appearance (see code):TS2503: Cannot find namespace 'myTypes'.
TS1147: Import declarations in a namespace cannot reference a module.
TS2307: Cannot find module './file-a.js' or its corresponding type declarations.
When the import statement is moved outside of the namespace, all errors disappear (makes sense from a JS point of view).
Beside this highlighted errors, only seen when opening the generated declaration files. Everything seems to work as intended (Type checking, auto-completion, etc.). Even when consuming the compiled library with the generated declaration files included (with those "errors" present).
Expected behavior:
No error to be present in generated declaration files.
Actual behavior:
Errors are present as explained above.
Playground Link: Not possible because import/export involved.
Related Issues: None.
Additional Details:
TypeScript Configuration
The text was updated successfully, but these errors were encountered: