Sajeetharan
Sajeetharan

Reputation: 222682

Declaration of public instance member function not allowed to appear after declaration of private instance member function

With angular2 app i have installed tslint extension for my vs code,

The app works fine, but tslint shows the line to correct,

import { Injectable } from '@angular/core';
@Injectable()
export class UserProfileService{
    constructor() {

    }
    getProfile() {
         return this.profile;
    }
    profile: Object = {
     profilePic: 'http://www.appresume.com/cv_templates/cv_2_1/conf/images/profile.jpg',
     firstName: 'John',
     lastName:'Doe',
     detailUrl : ''
  };
}

what is the fix?

Upvotes: 2

Views: 6892

Answers (1)

Oliver Cooke
Oliver Cooke

Reputation: 1059

It's good practice to scope your methods and variables as public, protected or private. TsLint has an opinion on how you order them usually in that very order.

Therefore move your object above your constructor define it as private (I assume it is as you have a method to return it) and define getProfile() as public leave that under your constructor. TsLint doesn't seem to care about the Constructor so doesn't need one but can have one if you want it to.

Hope that helps.

Upvotes: 7

Related Questions