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