google / google/closure-compiler
Cannot use template parameters to remove null
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
I'm not sure where this is breaking down. Maybe type parameters are always nullable???
```js
/**
* @param {?T} v
* @return {!T}
* @template T
*/
function notNull(v) {
if (v === null) {
throw new Error("null");
}
return v;
}
/**
* @param {!string} s
*/
function f(s) {
alert(s);
}
/**
* @param {?string} s
*/
function g(s) {
f(notNull(s)); // ERROR!
}
```
https://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520ADVANCED_OPTIMIZATIONS%250A%252F%252F%2520%2540output_file_name%2520default.js%250A%252F%252F%2520%2540formatting%2520pretty_print%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250A%250A%252F**%250A%2520*%2520%2540param%2520%257B%253FT%257D%2520v%250A%2520*%2520%2540return%2520%257B!T%257D%250A%2520*%2520%2540template%2520T%250A%2520*%252F%250Afunction%2520notNull(v)%2520%257B%250A%2520%2520if%2520(v%2520%253D%253D%253D%2520null)%2520%257B%250A%2520%2520%2509throw%2520new%2520Error(%2522null%2522)%253B%250A%2520%2520%257D%250A%2520%2520return%2520v%253B%250A%257D%250A%250A%252F**%250A%2520*%2520%2540param%2520%257B!string%257D%2520s%250A%2520*%252F%250Afunction%2520f(s)%2520%257B%250A%2520%2520alert(s)%253B%250A%257D%250A%250A%252F**%250A%2520*%2520%2540param%2520%257B%253Fstring%257D%2520s%250A%2520*%252F%250Afunction%2520g(s)%2520%257B%250A%2520%2520f(notNull(s))%253B%250A%257D%250A
Contributor guide
Assessment
This issue has not been assessed yet.