react-native - react native中typescript怎么声明全局变量
本文介绍了react-native - react native中typescript怎么声明全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
react native中typescript怎么声明全局变量,
我之前没有用TS,声明是通过global.xxx='xxx'
是可以的.
现在换成TS要怎么写呢?
我直接写global.xxx='xxx'
也是可以的,但是WS报了个错Error:(7, 8) TS2339:Property 'xxx' does not exist on type 'GlobalStatic'.
想问下正确的定义是怎么写的
解决方案
declare global {
namespace NodeJS {
interface Global {
xxx: string
}
}
}
这篇关于react-native - react native中typescript怎么声明全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文