我有以下行declare var notification: any;
。
在大多数情况下,它运行良好。但在 iOS 上,我看到以下异常 - ReferenceError: Can't findvariable:Notification
。 iOS 似乎不支持 Notification
,有没有办法检查它是否为 null,如果是则不声明它。像这样的东西 -
if (Notification)
declare var Notification: any;
最佳答案
声明它(编译时)
declare var Notification: any; // <= this is for the compiler only
测试它(运行时)
if (typeof Notification !== 'undefined') {
//non IOS stuff
}
关于javascript - 如果 Typescript 中不为 null,则声明环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38661097/