[英]ESLint like globals in TSLint
我正在使用来自cordova的设备插件,所以我有一个像这样的行let model = device.model || "";
let model = device.model || "";
导致Cannot find name 'device'.
错误。 我认为使用ESLint我需要做"eslintConfig": { "globals": { "device": true } }
但是那个TSLint对应的是什么?
我相信Cannot find name 'device'.
错误由TypeScript编译器生成,而不是由TSLint生成。 要解决缺少全局device
变量的问题,可以编写类型定义文件。 按照惯例,此文件名为globals.d.ts
。
在其中,输入以下代码:
declare let device: Device;
interface Device {
func: () => void;
prop: string;
}
将func
和prop
替换为您期望设备变量具有的函数和属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.