Skip to content

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

Open
@maximermilov

Description

@maximermilov
/**
 * @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

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

    Issue actions