google / google/closure-compiler

Compiler ignores object type if any attribute has dynamic name

Open
#2,389 0 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

See code below.
`anObject.shoudValidate()` has a non-null parameter.
It's called in `foobar()` with an optional one, but the compiler doesn't complain.

If you comment the dynamic attribute `['someOtherName']`, then the compilation fails.

```javascript
// ==ClosureCompiler==
// @output_file_name default.js
// @compilation_level ADVANCED_OPTIMIZATIONS
// ==/ClosureCompiler==

const anObject = {
/** @param {string} requiredValue */
shouldValidate: function(requiredValue) {},

['someOtherName']: function() {},
};

/** @param {?string} optionalValue */
function foobar(optionalValue) {
anObject.shouldValidate(optionalValue);
}
```

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.