Oauth Spartacus扩展授权服务

Oauth Spartacus扩展授权服务,oauth,authorize,spartacus-storefront,Oauth,Authorize,Spartacus Storefront,是否可以扩展身份验证服务并向其添加其他参数 当前正在尝试扩展,但遇到以下错误: src/app/service/auth/auth extend.service.ts(15,3)中出错:错误TS2416:类型“AuthExtendService”中的属性“authorize”不能分配给基类型“AuthService”中的同一属性 Type'(userId:string,password:string,countryCode:string,businessType:string)=>void'不可

是否可以扩展身份验证服务并向其添加其他参数

当前正在尝试扩展,但遇到以下错误:

src/app/service/auth/auth extend.service.ts(15,3)中出错:错误TS2416:类型“AuthExtendService”中的属性“authorize”不能分配给基类型“AuthService”中的同一属性

Type'(userId:string,password:string,countryCode:string,businessType:string)=>void'不可分配给Type'(userId:string,password:string)=>void'

src/app/service/auth/auth extend.service.ts(21,7):错误TS2345:类型为“{userId:string;password:string;countryCode:string;businessType:string;}”的参数不能分配给类型为“{userId:string;password:string;countryCode:string;businessType:string;}”的参数

对象文字只能指定已知属性,但类型“{userId:string;password:string;countryCode:string;businessType:string;}”中不存在“businessType”。你的意思是写“商业类型”吗?"


这里的任何人都会尝试这样做,比如添加新参数。

Typescript不支持这种开箱即用的重载。一种方法是使用可选参数,例如:

export class AuthExtendService extends AuthService {
  authorize(userId: string, password: string, businessType?: string): void {
    console.log(businessType);
    this.store.dispatch(
      new AuthActions.LoadUserToken({
        userId: userId,
        password: password,
      })
    );
  }  
}

这就是添加额外参数的方法。

尝试了此方法,但不起作用。我还尝试创建/重写LoadUserToken方法,并在其中添加了新参数,但仍然无效unsusccessful@marc_s你找到解决办法了吗?