简体   繁体   English

ESLint类似于TSLint中的全局变量

[英]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. funcprop替换为您期望设备变量具有的函数和属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “TSLint 仍然存在”=> 从 TSlint 升级到 ESLint - “TSLint still there” => upgrading from TSlint to ESLint Tslint 到 Eslint 迁移 - convert-tslint-to-eslint 命令后出错 - Tslint to Eslint migration - Error after convert-tslint-to-eslint command 如何运行@angular-eslint/schematics:convert-tslint-to-eslint - How to run @angular-eslint/schematics:convert-tslint-to-eslint Tslint 到 ESLint 迁移错误:未知选项 '--remove-tslint-if-no-more-tslint-targets' - Tslint to ESLint Migration Error : unknown option '--remove-tslint-if-no-more-tslint-targets' 在架构中找不到“tsconfig”-将 tslint 迁移到 eslint (Angular v11) - 'tsConfig' is not found in schema - Migrating tslint to eslint (Angular v11) Nx Angular TSLint 到 ESLint 迁移后的 Lint 错误 - Nx Angular Lint Error after TSLint to ESLint Migration Angular 12 从 tslint 切换到 eslint 后模板 linting 不起作用 - Angular 12 template linting not working after switchting from tslint to eslint 在Angular中用多个项目迁移TSLint到ESLint,ng lint命令挂起 - Migrate TSLint to ESLint in Angular with multiple projects, ng lint command hangs 将 angular 更新到 v14 后,TSlint 规则变为 ESlint - TSlint rules to ESlint after update angular to v14 如何手动更新 Angular 以使用 eslint 并删除 tslint - How to manually update Angular to use eslint and remove tslint
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM