Bad type annotation warnings for identifiers from re-exported modules
See original GitHub issueGiven:
// a.js
export default class A {
constructor() {
/** @type {string} */
this.message = 'Hello';
}
}
// b.js
import A from './a';
export {A};
// c.js
import {A} from './b';
class C {
/**
* @param {!A} a
*/
constructor(a) {
/** @const */
this.a = a;
}
}
console.log(new C(new A()).a.message);
Running:
java -jar path/to/compiler.jar \
--compilation_level ADVANCED \
--js *.js \
--language_out ECMASCRIPT5_STRICT \
--entry_point c.js
Yields:
c.js:5: WARNING - Bad type annotation. Unknown type A$$module$b
* @param {!A} a
^
0 error(s), 1 warning(s), 90.3% typed
'use strict';console.log((new function(a){this.a=a}(new function(){this.message="Hello"})).a.message);
It seems that closure is having some issues with types from re-exported modules from a different file. If I change the initial statement in c.js
to import A from './a'
the code compiles fine.
p.s. Sorry if this is a dupe; I searched through the current issues but missed anything pertaining to this.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Bad type annotation. Unknown type - javascript - Stack Overflow
The thing is that when I add a typedef I get warnings that myapp.dom is never defined but when I let the code...
Read more >The mypy command line - mypy 0.991 documentation
Mypy will recursively type check any submodules of the provided package. This flag is identical to --module apart from this behavior.
Read more >Mypy Documentation - Read the Docs
Mypy is a static type checker for Python. Type checkers help ensure that you're using variables and functions in your code correctly.
Read more >5.2. Warnings and sanity-checking - Haskell.org Downloads
Causes a warning to be emitted when a module, function or type with a WARNING or DEPRECATED pragma is used. See WARNING and...
Read more >Compiler Warnings by compiler version | Microsoft Learn
Consider moving that directive before the module declaration, or replace the textual inclusion with 'import <filename>;'.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I suspect the code we’re producing is correct; it just doesn’t typecheck well.
I don’t expect to have time to look at this in the near future but we should definitely fix it. Sometimes when an alias is annotated
@const
that helps the compiler to understand it’s supposed to be treated as an alias. So the first thing I’d try is running this example with--preserve_type_annotations
and see if we have those@const
annotations. If not, you can try going into the ProcessEs6Modules class and adding them. See https://github.com/google/closure-compiler/wiki/Writing-Compiler-Pass if you haven’t worked in the compiler code base before.Also - we most very much want to keep all 3 module systems at parity. Any fix/change needs to apply to all 3.