我使用的是nodeJS v12.10.0
这支持Intl.ListFormat
使用 Typescript v3.6.3
但是,当使用 typescript 进行编译时,我收到类型“typeof Intl”(ts2339)上不存在属性“ListFormat”错误。
我尝试谷歌搜索并发现this和其他建议,但没有任何效果。
我发现的共识似乎是使用 name.d.ts
文件并以某种方式扩展 Intl
对象,但我无法做到。
我仍在学习 typescript,但熟悉 javascript。
最佳答案
我发现接受的答案对我不起作用。我使用了以下内容:
declare namespace Intl {
class ListFormat {
constructor(locales?: string | string[], options?: Intl.ListFormatOptions);
public format: (items: string[]) => string;
}
}
关于javascript - 如何添加类型以在 Node v12 中使用 Intl.ListFormat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57964557/