繁体   English   中英

在 JSDoc @typedef 中使用导入的类型

[英]Using an imported type in JSDoc @typedef

我正在尝试减少在指定导入类型时的重复,如下所示,但出现错误

/**
@typedef {import("../types/util")} util
@typedef {util.mapBehaviors} mapBehaviors
... lots of other typedefs based on util
*/
'util' only refers to a type, but is being used as a namespace here.

这很奇怪,因为扩展导入显式有效:

/**
@typedef {import("../types/util").mapBehaviors} mapBehaviors
... lots of other typedefs
*/

如何将@typedef与导入的别名一起使用?

如果您仅从.d.ts文件中导出interfacetype ,而不是functionconst ,则可能会发生这种情况。

这将起作用:

/**
@typedef {import("../types/types").util} util
@typedef {util["mapBehaviors"]} mapBehaviors
...
*/

但只有在util.d.ts你有

export function mapBehaviors(tags: string[] | Behavior[], table: Behaviors): Behavior[]
...

代替

export interface mapBehaviors {
  (tags: string[] | Behavior[], table: Behaviors): Behavior[]
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM