【问题标题】:Constraining generics in Typescript JSDoc在 Typescript JSDoc 中约束泛型
【发布时间】:2018-12-22 06:59:23
【问题描述】:

我正在使用 JSDoc 形式的 TypeScript,并尝试使用扩展对象的泛型。我的编辑器给我一个 TypeScript 错误 index.js 代码声明 typeMyInterface<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);
}

【问题讨论】:

    标签: typescript jsdoc


    【解决方案1】:
    /**
     * @template {{a: number}} T
     * @param {MyInterface<T>} impl
     */
    

    @template 约束在pull request 24600 中实现

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-27
      • 2019-11-10
      • 2021-07-04
      • 2021-11-01
      • 2023-03-17
      • 2017-01-21
      • 1970-01-01
      相关资源
      最近更新 更多