closure-compiler icon indicating copy to clipboard operation
closure-compiler copied to clipboard

Instantiating templated function type has no effect

Open cpcallen opened this issue 1 year ago • 1 comments

Reproduction:

/**
 * @template T
 * @param {T} input
 * @return {T}
 */
function identity(input) {return input};

/** @typedef {typeof identity} */
var Identity;

var /** Identity<number> */ f;

const /** null */ _ = f;  // JSC_TYPE_MISMATCH: found: function(T): T

As far as I understand, the type of f should be function(number): number here.

See also discussion in closure-compiler-discuss@.

Aside: I thought there might be a better way to define the Identity type, but I can't see in the documentation any way to declare a templated function type directly. (But I would expect to be able successfully instantiate a templated type regardless of how it was declared.)

cpcallen avatar Mar 16 '23 13:03 cpcallen