[英]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
文件中導出interface
或type
,而不是function
或const
,則可能會發生這種情況。
這將起作用:
/**
@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.