Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

As the title states I get the following TSLint error:

'$http' cannot be declared in the constructor

I couldn't find anything related to this error on the internet.

Here's my code:

module MyModule {
    "use strict";

    class MyService {
        static $inject = ["$http"];
        constructor(private $http: ng.IHttpService) {
        }
    }
}
like image 898
david.s Avatar asked May 05 '15 09:05

david.s


Video Answer


1 Answers

Just as I posted the question I realized I need to check my tslint.json file and I found this:

"no-constructor-vars": true,

Apparently, this is documented on tslint's github page:

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

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

 "no-constructor-vars": false,
like image 199
david.s Avatar answered Nov 22 '22 20:11

david.s