ESLint like globals in TSLint
Asked Answered
A

1

19

I'm using device plugin from cordova so I have a line like this 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?

Aria answered 26/6, 2016 at 4:34 Comment(0)
Q
13

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.

Queston answered 11/2, 2017 at 22:38 Comment(2)
Where exactly should I put this globals.d.ts file?Ming
@Ming It needs to be in a location that is picked up by the TypeScript compiler. Commonly it is put in the root source folder.Queston

© 2022 - 2024 — McMap. All rights reserved.