[英]ESLint like globals in TSLint
I'm using device plugin from cordova so I have a line like this let model = device.model || "";
我正在使用来自cordova的设备插件,所以我有一个像这样的行
let model = device.model || "";
let model = device.model || "";
which causes Cannot find name 'device'.
导致
Cannot find name 'device'.
error. 错误。 I think with ESLint I would need to do
"eslintConfig": { "globals": { "device": true } }
but what is the TSLint counterpart of that? 我认为使用ESLint我需要做
"eslintConfig": { "globals": { "device": true } }
但是那个TSLint对应的是什么?
I believe the Cannot find name 'device'.
我相信
Cannot find name 'device'.
error is generated by the TypeScript compiler, not by TSLint. 错误由TypeScript编译器生成,而不是由TSLint生成。 To solve the problem of missing the global
device
variable you can write a type definition file. 要解决缺少全局
device
变量的问题,可以编写类型定义文件。 By convention this file is named globals.d.ts
. 按照惯例,此文件名为
globals.d.ts
。
In it, put the following code: 在其中,输入以下代码:
declare let device: Device;
interface Device {
func: () => void;
prop: string;
}
Replace func
and prop
with the functions and properties you expect the device variable to have. 将
func
和prop
替换为您期望设备变量具有的函数和属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.