question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bad type annotation warnings for identifiers from re-exported modules

See original GitHub issue

Given:

// 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:open
  • Created 7 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
MatrixFrogcommented, Jan 25, 2017

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.

0reactions
ChadKillingsworthcommented, Jan 25, 2017

Also - we most very much want to keep all 3 module systems at parity. Any fix/change needs to apply to all 3.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found