镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

JSdoc template defaults syntax not work #46574

Description

@xlfsummer

Bug Report

🔎 Search Terms

  • default for a type parameter
  • JSdoc default type parameter

🕗 Version & Regression Information

💻 Code

This is the demo code on your website

/** @template [T=object] */
class Cache { // hover `Cache` to see: 'class Cache <T = object>'
    /** @param {T} initial */
    constructor(T) {
    }
}
let c = new Cache()

When I copy those code, and use tsc to generate a .d.ts file. In that .d.ts file, Cache dose not have a generate template.

demo repo

🙁 Actual behavior

output .d.ts:

There is no template defaults, and event no template.

/** @template [T=object] */
export class Cache {
    /** @param {T} initial */
    constructor(T: any);
}

🙂 Expected behavior

output .d.ts should be:

/** @template [T=object] */
export class Cache<T = object> {
    /** @param {T} initial */
    constructor(T: any);
}

Activity

  1. IllusionMH commented on Oct 29, 2021

    @IllusionMH
    Contributor

    There is typo in code constructor(T) should be constructor(initial) (same as in handbook)

    And with PR merged on September 9 I think it's implemented only in 4.5. In 4.4.4 you should see an error for [ character.
    Works in 4.5.0-beta

  2. xlfsummer commented on Oct 29, 2021

    @xlfsummer
    Author

    I think it would be better to document a feature after it been released. 🙂

    And by the way I'm really exciting about this feature. ❤️

  3. locked as resolved and limited conversation to collaborators on Oct 21, 2025
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions