错误TS2322:类型'Observable <{} []>'无法分配给类型'Observable <Question []>'

时间:2019-08-13 12:23:04

标签: angular typescript

我正在构建git repo here并收到打字稿错误:

  

错误TS2322:类型为'Observable <{} []>

在下面的代码中不能指定返回语句上的类型Observable<Question[]>

getUsersAnsweredQuestion(userId: string, game: Game): 
Observable<Question[]> 
{
    const observables = [];
    for (const playerQnA of game.playerQnAs) {
      if (playerQnA.playerId === userId) {
        observables.push(this.checkUserQuestion(playerQnA));
      }
    }
    return forkJoin(observables);
}

我还没有修改代码,它是一个相当活跃的仓库,所以我想我配置了一些错误(我是TypeScript的新手,所以可能做的很愚蠢)。下面是显示我的版本和构建错误的CLI,

PS C:\files\projects\rwa-trivia-master-bitbucket\projects\trivia> ng v
     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / ? \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
Angular CLI: 7.1.4
Node: 10.16.2
OS: win32 x64
Angular: 7.1.4
... cli, common, compiler, compiler-cli, core, forms, http
... platform-browser, platform-browser-dynamic, platform-server
... router, service-worker, upgrade

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.11.4
@angular-devkit/build-angular      0.11.4
@angular-devkit/build-ng-packagr   0.11.4
@angular-devkit/build-optimizer    0.11.4
@angular-devkit/build-webpack      0.11.4
@angular-devkit/core               7.1.4
@angular-devkit/schematics         7.1.4
@angular/animations                7.2.15
@angular/cdk                       7.2.2
@angular/fire                      5.2.1
@angular/flex-layout               7.0.0-beta.24
@angular/material                  7.2.2
@angular/pwa                       0.11.4
@ngtools/json-schema               1.1.0
@ngtools/webpack                   7.1.4
@schematics/angular                7.1.4
@schematics/update                 0.11.4
ng-packagr                         4.7.1
rxjs                               6.5.2
typescript                         3.1.6
webpack                            4.23.1
PS C:\files\projects\rwa-trivia-master-bitbucket\projects\trivia> ng serve
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
 11% building modules 16/21 modules 5 active ...jects\trivia\src\styles\dark.theme.scssBrowserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist`
Date: 2019-08-13T12:15:34.045Z
Hash: 1b4220ca6a423442e401
Time: 11888ms
chunk {main} main.js, main.js.map (main) 1.91 kB [initial] [rendered]
chunk {polyfills} polyfills.js, polyfills.js.map (polyfills) 104 kB [initial] [rendered]
chunk {runtime} runtime.js, runtime.js.map (runtime) 6.08 kB [entry] [rendered]
chunk {styles} styles.js, styles.js.map (styles) 706 kB [initial] [rendered]
chunk {vendor} vendor.js, vendor.js.map (vendor) 324 kB [initial] [rendered]
ERROR in ../shared-library/src/lib/core/services/game.service.ts(247,5): error TS2322: Type 'Observable<{}[]>' is not assignable to type 'Observable<Question[]>'.
  Type '{}[]' is not assignable to type 'Question[]'.
    Type '{}' is not assignable to type 'Question'.
      Property 'id' is missing in type '{}'.

i ?wdm?: Failed to compile.

0 个答案:

没有答案