繁体   English   中英

X 类型的参数不能分配给 Y 类型的参数

[英]Argument of type X is not assignable to parameter of type Y

async acquireToken(request: AuthenticationParameters, redirect: any) {
  return msalApp.acquireTokenSilent(request).catch(error => {
    if (requiresInteraction(error.errorCode)) {
      return redirect
    } else {
      console.error('Non-interactive error:', error.errorCode)
    }
  });
}

错误:

Argument of type '(error: any) => void | Promise<AuthResponse>' is not assignable to parameter of type '(reason: any) => AuthResponse | PromiseLike<AuthResponse>'.

如何使类型可分配给它想要的参数类型?

您的函数必须返回AuthResponse或 Promise 之一。 您的错误处理程序有一个不返回任何内容的路径。 您应该在该路径中返回一些内容,如下所示:

async acquireToken(request: AuthenticationParameters, redirect: any) {
  return msalApp.acquireTokenSilent(request).catch(error => {
    if (requiresInteraction(error.errorCode)) {
      return redirect
    } else {
      console.error('Non-interactive error:', error.errorCode)
      return error
    }
  });
}

暂无
暂无

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

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