【问题标题】:ESLint like globals in TSLintESLint 类似于 TSLint 中的全局变量
【发布时间】:2016-10-28 08:40:40
【问题描述】:

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

【问题讨论】:

    标签: angular phonegap-plugins cordova-plugins eslint tslint


    【解决方案1】:

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

    在里面输入如下代码:

    declare let device: Device;
    
    interface Device {
      func: () => void;
      prop: string;
    }
    

    funcprop 替换为您希望设备变量具有的功能和属性。

    【讨论】:

    • 我应该把这个globals.d.ts文件放在哪里?
    • @Milkncookiez 它需要位于 TypeScript 编译器选择的位置。通常它放在根源文件夹中。
    猜你喜欢
    • 2014-09-24
    • 2017-05-23
    • 1970-01-01
    • 2022-11-16
    • 2017-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多