简体   繁体   English

声明私有实例成员函数后,不允许出现公共实例成员函数的声明

[英]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, 使用angular2 app我已经为我的vs代码安装了tslint扩展,

The app works fine, but tslint shows the line to correct, 该应用程序工作正常,但tslint显示要纠正的行,

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? 什么是修复?

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. TsLint对你如何按照这个顺序订购它们有一个意见。

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. 因此,将您的对象移到构造函数上方,将其定义为private(我假设它是一个返回它的方法)并将getProfile()定义为构造函数下的公共假。 TsLint doesn't seem to care about the Constructor so doesn't need one but can have one if you want it to. TsLint似乎并不关心构造函数,所以不需要一个,但如果你想要它可以有一个。

Hope that helps. 希望有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM