Skip to content

In JS, @template with @typedef is not equivalent to a generic type alias #23745

Closed
@sandersn

Description

@sandersn
/**
 * @template T
 * @typedef {[T, T]} TPair
 */
/** @type {TPair<number>} */
var tp = [1,2]

TPair doesn't correctly create a generic type alias.

Expected behavior:

TPair's typedef is equivalent to type TPair<T> = [T, T]

Actual behavior:

TPair's typedef is equivalent to type T; type TPair = [T, T] (where T is unique and inexpressible). So @type {TPair} is legal, but nothing can be assigned to it, and @type {TPair<number>} says that TPair is not generic.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions