首页 > 解决方案 > 类型 'never' 必须有一个返回迭代器的 '[Symbol.iterator]()' 方法。打字稿

问题描述

我有这个代码

authComplete$.subscribe(([user, loggedIn]) => {

显然,这只是导致错误所在行的不完整代码片段。错误是

Type 'never' must have a '[Symbol.iterator]()' method that returns an iterator.

我不知道如何解决这个问题。或者这甚至意味着什么

这是完整的代码和我到目前为止的研究

private handleAuthCallback() {
    // Call when app reloads after user logs in with Auth0
    const params = window.location.search;
    if (params.includes('code=') && params.includes('state=')) {
      let targetRoute: string; // Path to redirect to after login processsed
      const authComplete$ = this.handleRedirectCallback$.pipe(
        // Have client, now call method to handle auth callback redirect
        tap(cbRes => {
          // Get and set target redirect route from callback results
          targetRoute = cbRes.appState && cbRes.appState.target ? cbRes.appState.target : '/';
        }),
        concatMap(() => {
          // Redirect callback complete; get user and login status
          return combineLatest([
            this.getUser$(),
            this.isAuthenticated$
          ]);
        })
      );
      // Subscribe to authentication completion observable
      // Response will be an array of user and login status
      authComplete$.subscribe(([user, loggedIn]) => {     // <-- line error is on
        // Redirect to target route after callback processing
        this.router.navigate([targetRoute]);
      });
    }
  }

这是处理 auth0 角度整合示例,可以位于此处 https://auth0.com/docs/quickstart/spa/angular2

到目前为止,我的研究是在这个网站上进行的:

https://www.geekabyte.io/2019/06/typing-iterables-and-iterators-with.html

但说实话,读了几遍后,我更加困惑。

我确实看到我可能需要更改我在 tsconfig.json 文件中所做的 Angular 应用程序中的一些设置

"lib": [
      "es2018",
      "dom",
      "es5", "es6", "dom.iterable"
    ]

帮助将不胜感激

标签: angulartypescript

解决方案


所以我不确定这是否是解决方案,但我删除了用户并登录

authComplete$.subscribe(([user, loggedIn]) => {

就是现在:

authComplete$.subscribe() => {

我必须继续设置我的身份验证方案以查看代码是否可以工作或中断。一旦我得到我的答案,我将进一步详细说明这个答案。

然而,就代码编译删除数组而言确实有效。


推荐阅读