google / google/closure-compiler

Template type not inferred correctly when using (ConcreteType|T)

Open
#2,935 7 comments 0 reactions 0 assignees View on GitHub
bug P2
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

```javascript
/**
* @param {(T|undefined)} a
* @return {T}
* @throws {Error} when property is undefined.
* @template T
*/
function Required(a) {

if (a !== undefined) {
return a;
}
throw new Error('required property is undefined.');
};

/**
* @param {(number)} a
*/
function Test(a) {
}

var a = /** @type {number|undefined} */(11);
Test(Required(a))
```

This use too work, few month ago.
Now it produces warning:

```
input0:22: WARNING - actual parameter 1 of Test does not match formal parameter
found : (number|undefined)
required: number
Test(Required(a))
^^^^^^^^^^^

0 error(s), 1 warning(s), 86.6% typed
```

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.