gpt4 book ai didi

typescript - 我怎样才能在 typescript 中声明一个全局变量

转载 作者:搜寻专家 更新时间:2023-10-30 21:02:17 24 4
gpt4 key购买 nike

我在 typescript 中声明了一个全局变量,如下所示: global.test = “东西”我尝试这样做,但我收到错误属性“test”在类型“Global”上不存在。

最佳答案

I try to do that I get the error property ‘test’ does not exist on type ‘Global’.

globals.d.ts创建一个文件

interface Global {
test: string;
}

更多

声明文件:https://basarat.gitbook.io/typescript/docs/types/ambient/d.ts.html

关于typescript - 我怎样才能在 typescript 中声明一个全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44125398/

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