[英]Using an imported type in JSDoc @typedef
I'm trying to reduce duplication in specifying my imported types as follows but I'm getting an error我正在尝试减少在指定导入类型时的重复,如下所示,但出现错误
/**
@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.
It's weird because expanding the import explicitly works:这很奇怪,因为扩展导入显式有效:
/**
@typedef {import("../types/util").mapBehaviors} mapBehaviors
... lots of other typedefs
*/
How can I use @typedef
with an alias of an import?如何将
@typedef
与导入的别名一起使用?
This can happen if you are only exporting interface
or type
from your .d.ts
file and not function
or const
.如果您仅从
.d.ts
文件中导出interface
或type
,而不是function
或const
,则可能会发生这种情况。
This will work:这将起作用:
/**
@typedef {import("../types/types").util} util
@typedef {util["mapBehaviors"]} mapBehaviors
...
*/
but only if in util.d.ts
you have但只有在
util.d.ts
你有
export function mapBehaviors(tags: string[] | Behavior[], table: Behaviors): Behavior[]
...
instead of代替
export interface mapBehaviors {
(tags: string[] | Behavior[], table: Behaviors): Behavior[]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.