Skip to content

Support generic typedef #20831

Closed
Closed

Description

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.

Activity

  1. weswigham commented on Dec 21, 2017

    @weswigham
    Member

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

  2. weswigham commented on Dec 21, 2017

    @weswigham
    Member

    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.

  3. brendankenny commented on Jun 26, 2018

    @brendankenny
    Contributor

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

    /**
     * @template T
     * @typedef {T | null | undefined} Maybe
     */
    
    /** @type Maybe<number> */
    const x = 0;

    now works in latest.

  4. mhegazy commented on Jun 26, 2018

    @mhegazy
    Contributor

    Brendan Kenny (@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: JSDocRelates to JSDoc parsing and type generationFixedA PR has been merged for this issueSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions