TsLint: "$ http" cannot be declared in the constructor

As indicated in the header, I get the following TSLint error:

'$ http' cannot be declared in constructor

I could not find anything related to this error on the Internet.

Here is my code:

module MyModule { "use strict"; class MyService { static $inject = ["$http"]; constructor(private $http: ng.IHttpService) { } } } 
+6
source share
1 answer

As soon as I posted the question, I realized that I needed to check my tslint.json file and I found this:

 "no-constructor-vars": true, 

Apparently this is described on the tslint github page:

no-constructor-vars prohibits public and private modifiers for constructor parameters.

So the solution is to just disable no-constructor-vars :

  "no-constructor-vars": false, 
+10
source

Source: https://habr.com/ru/post/986558/


All Articles