google / google/closure-compiler

Plain Object and IObject are not compatible anymore?

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

Description

I didn't use the latest version of Closure Compiler for some time but I've upgraded to the latest version a I'm surprised by these warnings in my projects:
```javascript
/** @type {!IObject} */
var a = {};

/** @type {!IObject} */
var b = {
'foo' : 'bar'
};
```
```
test.js:2: WARNING - initializing variable
found : {}
required: IObject
var a = {};
^^

test.js:5: WARNING - initializing variable
found : {foo: string}
required: IObject
var b = {
^

0 error(s), 2 warning(s), 100.0% typed
```

But if I force the type, warnings disapear.
```javascript
/** @type {!IObject} */
var a = /** @type {!IObject} */ ({});

/** @type {!IObject} */
var b = /** @type {!IObject} */ ({
'foo' : 'bar'
});
```
```
0 error(s), 0 warning(s), 100.0% typed
```

Command line params:
```
--compilation_level ADVANCED \
--language_in ECMASCRIPT6_STRICT \
--language_out ECMASCRIPT5_STRICT \
--new_type_inf \
--source_map_format V3 \
--summary_detail_level 3 \
--use_types_for_optimization \
--warning_level VERBOSE
```

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.