Skip to content

Generic types from JSDoc aren't really generic #26883

@sandersn

Description

@sandersn
/**
 * @constructor
 * @template {string} K
 * @template V
 */
function Multimap() {
    /** @type {Object<string, V>} TODO: Remove the prototype from the fresh object */
    this._map = {};
};

var Ns = {}
/** @type {Multimap<"a" | "b", number>} */
const map = new Multimap();
const n = map._map['hi']

Expected behavior:
n: number

Actual behavior:
n: any in 3.0; n: V in 3.1-dev.

Types resolved from functions are never properly generic, even that function has @template-specified type parameters; they're only special-cased in a few places to produce a specific instantiation of a type. They should use the normal generic type machinery that Typescript does.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationDomain: JavaScriptThe issue relates to JavaScript specifically

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions