google / google/closure-compiler
@record type with unused template parameter fails type inference
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
I have an `@record` type with a template parameter which is not yet used.
I can't get an object literal to infer to that type when calling a method with an inferred type parameter.
``` js
/** @constructor @template T */
function EventType() {}
/** @struct @record @template MODEL */
function ChangeEventArgs() {};
/** @const {number} */
ChangeEventArgs.prototype.reason;
/**
* @param {!EventType} type
* @param {T} args
* @template T
*/
function notify(type, args){}
/** @const {!EventType>} */
const eventType = new EventType();
notify(eventType, {reason: 0});
/** @const {!ChangeEventArgs} */
const works = {reason: 0};
```
``` js
input0:21: WARNING - actual parameter 1 of notify does not match formal parameter
found : EventType>
required: EventType<(ChangeEventArgs|{reason: number})>
notify(eventType, {reason: 0});
^
```
https://closure-compiler-debugger.appspot.com/#input0%3D%252F**%2520%2540constructor%2520%2540template%2520T%2520*%252F%250Afunction%2520EventType()%2520%257B%257D%250A%250A%250A%252F**%2520%2540struct%2520%2540record%2520%2540template%2520MODEL%2520*%252F%250Afunction%2520ChangeEventArgs()%2520%257B%257D%253B%250A%252F**%2520%2540const%2520%257Bnumber%257D%2520*%252F%250AChangeEventArgs.prototype.reason%253B%250A%250A%250A%252F**%250A%2520*%2520%2540param%2520%257B!EventType%253CT%253E%257D%2520type%250A%2520*%2520%2540param%2520%257BT%257D%2520args%250A%2520*%2520%2540template%2520T%250A%2520*%252F%250Afunction%2520notify(type%252C%2520args)%257B%257D%250A%250A%252F**%2520%2540const%2520%257B!EventType%253C!ChangeEventArgs%253Cstring%253E%253E%257D%2520*%252F%250Aconst%2520eventType%2520%253D%2520new%2520EventType()%253B%250A%250Anotify(eventType%252C%2520%257Breason%253A%25200%257D)%253B%250A%250A%252F**%2520%2540const%2520%257B!ChangeEventArgs%253Cstring%253E%257D%2520*%252F%250Aconst%2520works%2520%253D%2520%257Breason%253A%25200%257D%253B%250A%26input1%26conformanceConfig%26externs%26refasterjs-template%26includeDefaultExterns%3D1%26CHECK_SYMBOLS%3D1%26CHECK_TYPES%3D1%26CLOSURE_PASS%3D1%26LANG_IN_IS_ES6%3D1%26MISSING_PROPERTIES%3D1%26PRESERVE_TYPE_ANNOTATIONS%3D1%26PRETTY_PRINT%3D1%26TRANSPILE%3D1
Contributor guide
Assessment
This issue has not been assessed yet.