Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instantiating templated function type has no effect #4070

Open
cpcallen opened this issue Mar 16, 2023 · 1 comment
Open

Instantiating templated function type has no effect #4070

cpcallen opened this issue Mar 16, 2023 · 1 comment

Comments

@cpcallen
Copy link
Contributor

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.)

@mhausner
Copy link
Contributor

This is not supported in the JSCompiler type system. The Identity annotation should generate a type error, but currently does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants