简体   繁体   中英

ESLint like globals in TSLint

I'm using device plugin from cordova so I have a line like this let model = device.model || ""; let model = device.model || ""; which causes 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?

I believe the Cannot find name 'device'. error is generated by the TypeScript compiler, not by TSLint. To solve the problem of missing the global device variable you can write a type definition file. By convention this file is named 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM