ESLint类似于TSLint中的全局变量

apr*_*reg 17 phonegap-plugins eslint cordova-plugins tslint angular

我正在使用来自cordova的设备插件,所以我有这样的一行let model = device.model || "";会导致Cannot find name 'device'.错误.我认为使用ESLint我需要做 "eslintConfig": { "globals": { "device": true } } 但是TSLint对应的是什么?

Dav*_*ots 10

我相信Cannot find name 'device'.错误是由TypeScript编译器生成的,而不是由TSLint生成的.要解决缺少全局device变量的问题,可以编写类型定义文件.按照惯例,此文件已命名globals.d.ts.

在其中,输入以下代码:

declare let device: Device;

interface Device {
  func: () => void;
  prop: string;
}
Run Code Online (Sandbox Code Playgroud)

替换funcprop期望设备变量具有的功能和属性.