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

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

使用 angular2 应用程序,我已经为我的 vs 代码安装了 tslint 扩展,

该应用运行良好,但 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 : ''
  };
}

修复方法是什么?

最好将方法和变量的范围限定为 public、受保护或私有。 TsLint 对您通常如何按该顺序对它们进行排序有自己的看法。

因此将你的对象移到你的构造函数之上,将其定义为私有(我假设它是因为你有一个 return 它的方法)并将 getProfile() 定义为 public 将其留在你的构造函数下. TsLint 似乎并不关心构造函数,因此不需要构造函数,但如果需要,可以拥有一个。

希望对您有所帮助。