TsLint: '$http' cannot be declared in the constructor
Asked Answered
U

1

6

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) {
        }
    }
}
Upandcoming answered 5/5, 2015 at 9:14 Comment(0)
U
11

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,
Upandcoming answered 5/5, 2015 at 9:21 Comment(1)
no-constructor-vars has been renamed to no-parameter-properties, see github.com/palantir/tslint/issues/1296Piscator

© 2022 - 2024 — McMap. All rights reserved.