typescript - TsLint: '$http' 不能在构造函数中声明

标签 typescript tslint

如标题所述,我收到以下 TSLint 错误:

'$http' cannot be declared in the constructor

我在互联网上找不到与此错误相关的任何信息。

这是我的代码:

module MyModule {
    "use strict";

    class MyService {
        static $inject = ["$http"];
        constructor(private $http: ng.IHttpService) {
        }
    }
}

最佳答案

就在我发布问题时,我意识到我需要检查我的 tslint.json 文件,我发现了这个:

"no-constructor-vars": true,

显然,这记录在 tslint's github page 上:

no-constructor-vars disallows the public and private modifiers for constructor parameters.

所以解决方案就是禁用no-constructor-vars:

 "no-constructor-vars": false,

关于typescript - TsLint: '$http' 不能在构造函数中声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30048785/

相关文章:

Angular:Async Await- promise 中的 EventListener

typescript - 具有枚举类型问题的 Ngrx 操作

javascript - tslint CLI 和 jest CLI 不适用于 iterm zsh macOS

tslint - 如何使用 prettier 在类中的方法声明之后和之前添加新行?

javascript - 找不到配置中指定的以下规则的实现

typescript - VSCode、Prettier 和 TSLint : formatOnSafe messes up auto sort of imports

javascript - 为什么我不能走子组件的路线?

angular - onSubmit 未定义(Angular 6)

javascript - 如何在React中使用forwardRef输入多个引用?

typescript - Visual Studio代码禁用对象解构的代码格式