google / google/closure-compiler

Bad type annotation warnings for identifiers from re-exported modules

Open
#2,257 6 comments 0 reactions 0 assignees View on GitHub
ES6
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Given:

```js
// a.js
export default class A {
constructor() {
/** @type {string} */
this.message = 'Hello';
}
}
```

```js
// b.js
import A from './a';

export {A};
```

```js
// 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:

```sh
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.