我正在使用 TypeScript 的 JSDoc 形式,并尝试使用扩展对象的泛型。我的编辑器给了我一个 TypeScript 错误,用于index.js声明 type 参数的代码MyInterface<T>,说Type 'T' does not satisfy the constraint '{ 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);
}
Run Code Online (Sandbox Code Playgroud)
/**
* @template {{a: number}} T
* @param {MyInterface<T>} impl
*/
Run Code Online (Sandbox Code Playgroud)
@template在拉取请求 24600中实施了约束
| 归档时间: |
|
| 查看次数: |
1224 次 |
| 最近记录: |