google / google/closure-compiler
Compiler believes variable can be undefined in map
Open
Types
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
Given an array `foo` and a variable `bar` of type `{!Object|undefined}`, the following code
``` javascript
doSomething() {
if (!bar) {
return;
}
return foo.map(element => transform(element, bar));
}
/**
* @param {!Object}
*/
transform(element, bar) {
return ...;
}
```
Fails compilation because closure compiler insists that `bar` can not be passed to `transform` because it may be `undefined`, which is obviously not the case / impossible.
Contributor guide
Assessment
This issue has not been assessed yet.