google / google/closure-compiler

Compiler believes variable can be undefined in map

Open
#1,977 2 comments 0 reactions 0 assignees View on GitHub
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

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.