且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

是否可以约束jsDoc @template声明中定义的泛型类型?

更新时间:2022-12-23 14:33:55

从TypeScript 2.9开始,现在似乎可以使用TypeScript来约束模板参数(请参见

As of TypeScript 2.9 it seems constraining template parameters is now possible using TypeScript (see issue 24600). The above TypeScript declaration would therefor become:

/**
 * @template T
 * @typedef {new(...args: any[]) => T} Constructor
 **/

/**
 * @template {Constructor<{}>} T
 * @param {T} Base
 */
function Tagged(Base) { … }