在Typescript JSDoc中约束泛型
我正在使用TypeScript的JSDoc形式,并尝试使用扩展对象的泛型。我的编辑器为声明类型为在Typescript JSDoc中约束泛型,typescript,jsdoc,Typescript,Jsdoc,我正在使用TypeScript的JSDoc形式,并尝试使用扩展对象的泛型。我的编辑器为声明类型为MyInterface的参数的index.js代码提供了一个TypeScript错误,表示type'T'不满足约束“{a:number;}”。 如何指定接受约束JSDoc TypeScript中对象的通用参数 // index.d.ts declare interface MyInterface<T extends {a: number}> { b: string; } // in
MyInterface
的参数的index.js
代码提供了一个TypeScript错误,表示type'T'不满足约束“{a:number;}”。
如何指定接受约束JSDoc TypeScript中对象的通用参数
// index.d.ts
declare interface MyInterface<T extends {a: number}> {
b: string;
}
// index.js
/**
* @template T
* @param {MyInterface<T>} impl
*/
function doStuff(impl) {
console.log(impl);
}
//index.d.ts
声明接口MyInterface{
b:弦;
}
//index.js
/**
*@T模板
*@param{MyInterface}impl
*/
函数doStuff(impl){
console.log(impl);
}
/**
*@template{{a:number}}T
*@param{MyInterface}impl
*/
@模板
约束已在中实现
/**
* @template {{a: number}} T
* @param {MyInterface<T>} impl
*/