在JSDOC @TyPedef中使用导入类型

发布于 2025-01-28 14:33:45 字数 552 浏览 1 评论 0原文

我正在尝试减少重复,以指定我的导入类型如下,但是我遇到了一个错误,

/**
@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与导入的别名使用?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷你仙 2025-02-04 14:33:45

如果您仅导出接口type来自.d.d.ts文件而不是function> 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[]
}

This can happen if you are only exporting interface or type from your .d.ts file and not function or const.

This will work:

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

but only if in util.d.ts you have

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

instead of

export interface mapBehaviors {
  (tags: string[] | Behavior[], table: Behaviors): Behavior[]
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文