gpt4 book ai didi

typescript - typescript 中的全局类型

转载 作者:搜寻专家 更新时间:2023-10-30 20:33:12 25 4
gpt4 key购买 nike

有没有办法在您的 typescript 文件中创建一个定义全局可访问类型的文件?

我喜欢 typescript ,但发现当我想要真正的类型安全时,我必须显式地从整个系统导入类型。这很烦人。

最佳答案

是的,这是可能的。您可以在这里找到所有信息:https://www.typescriptlang.org/docs/handbook/declaration-files/templates/global-modifying-module-d-ts.html

重要的是:

declare global {
/*~ Here, declare things that go in the global namespace, or augment
*~ existing declarations in the global namespace
*/
interface String {
fancyFormat(opts: StringFormatOptions): string;
}
}

关于typescript - typescript 中的全局类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42984889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com