【问题标题】:Declaration of public instance member function not allowed to appear after declaration of private instance member function公共实例成员函数的声明不允许出现在私有实例成员函数的声明之后
【发布时间】:2017-01-24 19:41:42
【问题描述】:

使用 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 : ''
  };
}

解决方法是什么?

【问题讨论】:

  • 是在整个代码中显示还是在特定代码行加了下划线?
  • 它为配置文件对象显示
  • profile: Object = { profilePic: 'appresume.com/cv_templates/cv_2_1/conf/images/profile.jpg', firstName: 'John', lastName: 'Doe', detailUrl: '' };试试看,我在“Doe”之前添加了空格。对我来说没有错误。

标签: angular typescript tslint


【解决方案1】:

将您的方法和变量限定为公共、受保护或私有是一种很好的做法。 TsLint 对您通常如何按该顺序订购它们有意见。

因此,将您的对象移到构造函数之上,将其定义为私有(我假设它是因为您有一个返回它的方法)并将 getProfile() 定义为公共,离开构造函数。 TsLint 似乎并不关心构造函数,因此不需要它,但如果你愿意,可以拥有它。

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2021-08-05
    • 1970-01-01
    • 1970-01-01
    • 2015-10-09
    • 1970-01-01
    • 1970-01-01
    • 2011-11-23
    • 2011-10-30
    • 1970-01-01
    相关资源
    最近更新 更多