Typescript eslint成员排序陷阱-无论哪个声明先出现,都会导致错误
我有这个密码:Typescript eslint成员排序陷阱-无论哪个声明先出现,都会导致错误,typescript,eslint,typescript-eslint,Typescript,Eslint,Typescript Eslint,我有这个密码: export class RouteParamsService { private routeParamsChangeSource = new ReplaySubject<Params>() // lets call this line 1 routeParamsChange$ = this.routeParamsChangeSource.asObservable() // lets call this line 2 ... etc } 导出类Route
export class RouteParamsService {
private routeParamsChangeSource = new ReplaySubject<Params>() // lets call this line 1
routeParamsChange$ = this.routeParamsChangeSource.asObservable() // lets call this line 2
... etc
}
导出类RouteParamsService{
private routeParamsChangeSource=new ReplaySubject()//让我们调用第1行
routeParamsChange$=this.routeParamsChangeSource.asObservable()//让我们调用第2行
等
}
如果我将第1行放在第2行之前,我会得到错误:
@typescript eslint/成员排序
应在所有私有实例字段定义之前声明成员routeParamsChange$
如果我将第2行放在第1行之前,我会得到错误:
属性routeParamsChangeSource在初始化之前使用
我理解这两个错误,以及为什么我会得到它们。然而,有没有一条规则可以放松这些规则,但只有当你陷入这样的陷阱时才可以?我知道我可以做eslint disable line@typescript eslint/成员排序
,但我不想每次遇到这个问题(我经常碰到这个问题)时都要这样做
我也不想公开routeParamsChangeSource
有什么想法吗?谢谢
@typescript eslint/成员排序
lint规则当前不理解字段之间的依赖关系
正如您所理解的,这种依赖性会产生一个复杂的排序问题,社区中还没有人有足够的动力来解决这个问题
您可以在此处看到跟踪它的问题:
如果这是一个对你来说很重要的问题,这个项目欢迎捐款
至于实际的解决方法或修复 禁用注释是一个很好的临时措施 另一种选择是将依赖项移动到构造函数中:
export class RouteParamsService {
private routeParamsChangeSource = new ReplaySubject<Params>();
routeParamsChange$;
constructor() {
this.routeParamsChange$ = this.routeParamsChangeSource.asObservable();
}
}
导出类RouteParamsService{
private routeParamsChangeSource=新的ReplaySubject();
routeParamsChange$;
构造函数(){
this.routeParamsChange$=this.routeParamsChangeSource.asObservable();
}
}