簡體   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