google / google/closure-compiler
Do better inference for effectively-final escaped variables.
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
[example][1]
```js
/** @param {string|number} x */
function f(x) {
if (typeof x == 'string') {
var /** function(): string */ y =
function() { return x; };
}
}
```
The variable `x` is effectively final, since it's never reassigned in its lifetime. So the closure should inherit this from the flow scope where it is defined. Instead, we get an error that `x` needs to be `string` but it's actually `string|number`.
[1]: https://closure-compiler-debugger.appspot.com/#input0%3D%252F**%2520%2540param%2520%257Bstring%257Cnumber%257D%2520x%2520*%252F%250Afunction%2520f(x)%2520%257B%250A%2520%2520if%2520(typeof%2520x%2520%253D%253D%2520'string')%2520%257B%250A%2520%2520%2520%2520var%2520%252F**%2520function()%253A%2520string%2520*%252F%2520y%2520%253D%250A%2520%2520%2520%2520%2520%2520%2520%2520function()%2520%257B%2520return%2520x%253B%2520%257D%253B%250A%2520%2520%257D%250A%257D%26input1%26conformanceConfig%26externs%26refasterjs-template%26CHECK_SYMBOLS%3Dtrue%26MISSING_PROPERTIES%3Dtrue%26TRANSPILE%3Dtrue%26CHECK_TYPES%3Dtrue%26CLOSURE_PASS%3Dtrue%26PRESERVE_TYPE_ANNOTATIONS%3Dtrue%26PRETTY_PRINT%3Dtrue
Contributor guide
Assessment
This issue has not been assessed yet.