Skip to content

@record type with unused template parameter fails type inference #1836

@SLaks

Description

@SLaks
Contributor

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.

/** @constructor @template T */
function EventType() {}


/** @struct @record @template MODEL */
function ChangeEventArgs() {};
/** @const {number} */
ChangeEventArgs.prototype.reason;


/**
 * @param {!EventType<T>} type
 * @param {T} args
 * @template T
 */
function notify(type, args){}

/** @const {!EventType<!ChangeEventArgs<string>>} */
const eventType = new EventType();

notify(eventType, {reason: 0});

/** @const {!ChangeEventArgs<string>} */
const works = {reason: 0};
input0:21: WARNING - actual parameter 1 of notify does not match formal parameter
found   : EventType<ChangeEventArgs<string>>
required: EventType<(ChangeEventArgs<string>|{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

Activity

changed the title [-]Templated @record types fail inference with other templates[/-] [+]@record type with unused template parameter fails type inference[/+] on Jun 9, 2016
dimvar

dimvar commented on Jun 10, 2016

@dimvar
Contributor

FYI, this works correctly in the new type inference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @dimvar@SLaks

        Issue actions

          @record type with unused template parameter fails type inference · Issue #1836 · google/closure-compiler