VSCode 哈希图自动完成功能不起作用

发布于 2025-01-20 18:49:59 字数 667 浏览 2 评论 0原文

我不确定我在哪里做错了。这是我的代码。

type.d.ts:

type _MaterialTable = {
    weight: number
    price: number
}
type Material = {
    [index: string]: _MaterialTable
}

test.js:

/** @type {Material} */
WeightTable = {};
/** @type {map<string, _MaterialTable} */
WeightTable2 = {}

const x1 = WeightTable['test'];
const x2 = WeightTable2['test'];

enter image description here

The result was always any type.不是_MaterialTable类型。

我该如何正确键入?谢谢

I am not sure where I did wrong.. This below is my code.

type.d.ts:

type _MaterialTable = {
    weight: number
    price: number
}
type Material = {
    [index: string]: _MaterialTable
}

test.js:

/** @type {Material} */
WeightTable = {};
/** @type {map<string, _MaterialTable} */
WeightTable2 = {}

const x1 = WeightTable['test'];
const x2 = WeightTable2['test'];

enter image description here

The result was always any type. Not _MaterialTable type.

How can I type this properly? Thank you

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文