打字稿中的全局类型

塔尔:

有没有一种方法可以在您的打字稿文件中创建定义全局可访问类型的文件?

我喜欢打字稿,但是发现当我想真正实现打字安全时,必须从整个系统中显式导入打字稿。真烦人。

塞巴斯蒂安·塞巴尔德(Sebastian Sebald):

是的,这是可能的。您可以在此处找到所有信息: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;
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章