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) {
        }
    }
}

1 Answer 1

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,
Sign up to request clarification or add additional context in comments.

1 Comment

no-constructor-vars has been renamed to no-parameter-properties, see github.com/palantir/tslint/issues/1296

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.