Skip to content

Support generic typedef #20831

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

Closed
ghost opened this issue Dec 20, 2017 · 4 comments
Closed

Support generic typedef #20831

ghost opened this issue Dec 20, 2017 · 4 comments
Labels
Domain: JSDoc Relates to JSDoc parsing and type generation Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@ghost
Copy link

ghost commented Dec 20, 2017

TypeScript Version: 2.7.0-dev.20171220

Code

/** @typedef {T | null | undefined} Maybe<T> */

/** @type Maybe<number> */
const x = 0;

Expected behavior:

No error.

Actual behavior:

a.js(1,15): error TS2304: Cannot find name 'T'.
a.js(3,11): error TS2315: Type 'Maybe' is not generic.
@ghost ghost added Salsa labels Dec 20, 2017
@weswigham
Copy link
Member

weswigham commented Dec 21, 2017

@Andy-MS In your example, I'm pretty sure you're supposed to introduce the T in the @typedef with an @template tag.

@weswigham
Copy link
Member

weswigham commented Dec 21, 2017

Scratch that, I don't think closure supports generic typedefs at all. But if we're talking about enabling it in a jsdocy way, I'm pretty sure the template tag is where you'd introduce your type argument list.

@weswigham weswigham added the Domain: JSDoc Relates to JSDoc parsing and type generation label Dec 21, 2017
@mhegazy mhegazy added Suggestion An idea for TypeScript and removed feature-request labels Jan 4, 2018
@brendankenny
Copy link
Contributor

I believe this is now fixed (by #24600?). @weswigham's closure example

/**
 * @template T
 * @typedef {T | null | undefined} Maybe
 */

/** @type Maybe<number> */
const x = 0;

now works in latest.

@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Jun 26, 2018
@mhegazy mhegazy added this to the TypeScript 3.0 milestone Jun 26, 2018
@mhegazy mhegazy closed this as completed Jun 26, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Jun 26, 2018

@brendankenny's comment in #20831 (comment) is the expected format to declare a generic type parameter in a type def.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: JSDoc Relates to JSDoc parsing and type generation Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants