更新到Angular 9后的reducer问题

梅根·贝利(Megan Bailey)

编译应用程序时出现以下错误。我不确定这到底是什么意思。我对angular非常陌生,我正在尝试将一些旧代码更新为新版本的angular。任何方向将不胜感激。

    src/app/app.module.ts:30:9 - error TS2322: Type '{ app: typeof AppState; }' is not 
    assignable to type 'InitialState<{ app: AppState; }>'.
    Type '{ app: typeof AppState; }' is not assignable to type 'Partial<{ app: AppState; }>'.
    Types of property 'app' are incompatible.
      Property 'app' is missing in type 'typeof AppState' but required in type 'AppState'
    30 initialState: {
       ~~~~~~~~~~~~
     src/app/core/store/crumboard-store.model.ts:139:3
    139   app: {
          ~~~
    'app' is declared here.
    node_modules/@ngrx/store/src/store_module.d.ts:23:5
    23     initialState?: InitialState<T>;
           ~~~~~~~~~~~~
    The expected type comes from property 'initialState' which is declared here on type 
    'RootStoreConfig<{ app: AppState; }, Action>

这些是我的文件--app.module.ts

import { NgModule } from "@angular/core";
import { InitialState } from "@ngrx/store/src/models";
import { AppComponent } from "./app.component";
import { CrumboardReducer, AppState } from "./core/store";
import { DataStatus } from "./core/store";

@NgModule({
  declarations: [AppComponent],
  imports: [
    SmgnCoreModule,
    SmgnSharedModule,
    LoginModule,
    PasswordModule,
    DashboardModule,
    AppRoutingModule,
    StoreModule.forRoot(
      {
        app: CrumboardReducer
      },
      {
        initialState: {
          app: {}
        }
      }
    )
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
  • crumboard-store.module
import { Action, State } from "@ngrx/store";

export class StateItem<T> {
  type: CrumboardActionTypes;
  status: DataStatus;
  data: T;
  error: Error;
export class AppState {
  app: {
    ACTIVE_PROJECT: StateItem<IApiProject>;
    ACTIVE_TIME_APPROVAL_PROJECT: StateItem<IProjectTimeApprovalTimesheets>;
    ACTIVE_TIMESHEET: StateItem<ITimesheet>;
    ACTIVE_USER: StateItem<User>;
    ASSOCIATED_PROJECTS: StateItem<AssociatedProject[]>;
    CLIENTS: StateItem<IApiClient[]>;
    ESTIMATES: StateItem<IApiEstimateListItem>;
    EXPENSE_CATEGORIES: StateItem<IApiExpenseCategoryItem[]>;
    EXPENSE: StateItem<IApiExpense[]>;
    MARGIN_REPORT: StateItem<IMarginReport>;
    PROJECT_TIMESHEET_SUBMISSIONS: StateItem<IProjectTimeApprovalListItem[]>;
    PROJECTS: StateItem<IApiProjectListItem>;
    QBO_AUTH: StateItem<void>;
    QUICKBOOKS_VENDOR: StateItem<QBOVendor[]>;
    QUICKBOOKS_SERVICE: StateItem<QBOService[]>;
    QUICKBOOKS_EMPLOYEE: StateItem<QBOEmployee[]>;
    QUICKBOOKS_CUSTOMER: StateItem<QBOCustomer[]>;
    QUICKBOOKS_EXPENSE_CATEGORIES: StateItem<QBOExpenseCategory[]>;
    RESOURCE_TYPES: StateItem<ResourceType>;
    TIME_APPROVAL_TEAM_TIMESHEET_LIST: StateItem<TimeApprovalTeamTimesheetList>;
    TIME_APPROVALS: StateItem<IProjectTimeApprovalListItem[]>;
    TIME_TRACKING_REPORT: StateItem<ITimeTrackingReport>;
    UNSUBMITTED_PROJECT_TIMESHEETS: StateItem<IApiTimesheet>;
    UNSUBMITTED_TIMESHEET_EMAIL_REMINDER: StateItem<IApiTimesheet[]>;
    USER_PROJECTS: StateItem<IApiUserProject[]>;
    USERS: StateItem<IApiUserListItem[]>;
  };
}
  • 来自ngrx:@ ngrx / store / src / store_module.d.ts

  • 最后,我的package.json

{
  "name": "resourceryweb",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "dev": "ng build --dev --build-optimizer --aot",
    "staging": "ng build -e=staging --build-optimizer --aot",
    "prod": "ng build -e=prod --build-optimizer --aot",
    "lint": "ng lint",
    "hmr": "ng serve --hmr -e=hmr"
  },
  "private": true,
  "dependencies": {
    "@angular-devkit/build-angular": "~0.900.3",
    "@angular/animations": "^9.0.2",
    "@angular/cdk": "^9.0.1",
    "@angular/common": "9.0.2",
    "@angular/compiler": "9.0.2",
    "@angular/core": "9.0.2",
    "@angular/flex-layout": "^9.0.0-beta.29",
    "@angular/forms": "9.0.2",
    "@angular/material": "^9.0.1",
    "@angular/material-moment-adapter": "~9.0.1",
    "@angular/platform-browser": "9.0.2",
    "@angular/platform-browser-dynamic": "9.0.2",
    "@angular/router": "9.0.2",
    "@auth0/angular-jwt": "~1.1.0",
    "@ngrx/store": "~8.6.0",
    "@types/moment-duration-format": "^2.2.2",
    "core-js": "~2.4.1",
    "lodash": "^4.17.15",
    "material-design-icons": "~3.0.1",
    "moment": "~2.24.0",
    "moment-duration-format": "^2.3.2",
    "ng2-dnd": "^5.0.2",
    "node-sass": "^4.13.1",
    "rxjs": "~6.5.4",
    "rxjs-compat": "^6.0.0-rc.0",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/core": "0.5.7",
    "@angular/cli": "^9.0.3",
    "@angular/compiler-cli": "9.0.2",
    "@angular/language-service": "9.0.2",
    "@angularclass/hmr": "^2.1.3",
    "@types/node": "^12.12.28",
    "codelyzer": "^5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.7.0",
    "typescript": "3.7.5"
  }
}

看起来好像是类型不匹配,但是通过遍历似乎可以为我提供正确的类型或在更改期间发生的语法更改。任何帮助将不胜感激

梅根·贝利(Megan Bailey)

解决方案是添加一个“?” 允许AppState为null。

export class AppState {
    app?: {
        ACTIVE_PROJECT: StateItem<IApiProject>;
        ACTIVE_TIME_APPROVAL_PROJECT: StateItem<IProjectTimeApprovalTimesheets>;
        ACTIVE_TIMESHEET: StateItem<ITimesheet>;
        ACTIVE_USER: StateItem<User>;
        ASSOCIATED_PROJECTS: StateItem<AssociatedProject[]>;
        CLIENTS: StateItem<IApiClient[]>;
        ESTIMATES: StateItem<IApiEstimateListItem>;
        EXPENSE_CATEGORIES: StateItem<IApiExpenseCategoryItem[]>;
        EXPENSE: StateItem<IApiExpense[]>;
        MARGIN_REPORT: StateItem<IMarginReport>;
        PROJECT_TIMESHEET_SUBMISSIONS: StateItem<IProjectTimeApprovalListItem[]>;
        PROJECTS: StateItem<IApiProjectListItem>;
        QBO_AUTH: StateItem<void>;
        QUICKBOOKS_VENDOR: StateItem<QBOVendor[]>;
        QUICKBOOKS_SERVICE: StateItem<QBOService[]>;
        QUICKBOOKS_EMPLOYEE: StateItem<QBOEmployee[]>;
        QUICKBOOKS_CUSTOMER: StateItem<QBOCustomer[]>;
        QUICKBOOKS_EXPENSE_CATEGORIES: StateItem<QBOExpenseCategory[]>;
        RESOURCE_TYPES: StateItem<ResourceType>;
        TIME_APPROVAL_TEAM_TIMESHEET_LIST: StateItem<TimeApprovalTeamTimesheetList>;
        TIME_APPROVALS: StateItem<IProjectTimeApprovalListItem[]>;
        TIME_TRACKING_REPORT: StateItem<ITimeTrackingReport>;
        UNSUBMITTED_PROJECT_TIMESHEETS: StateItem<IApiTimesheet>;
        UNSUBMITTED_TIMESHEET_EMAIL_REMINDER: StateItem<IApiTimesheet[]>;
        USER_PROJECTS: StateItem<IApiUserProject[]>;
        USERS: StateItem<IApiUserListItem[]>;
      };
    }

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

更新到Angular 9

来自分类Dev

从Angular 8更新到Angular 9后,“ ng generate component”会生成.css文件而不是.scss

来自分类Dev

更新到 angular 4 后找不到 platformUniversalDynamic

来自分类Dev

更新到 Angular 8 CLI 后抛出“.getColorDepth is not a function”

来自分类Dev

从V8更新到V9后,Angular App无法编译

来自分类Dev

更新到Swift 3后的问题

来自分类Dev

更新到XCode 6后Moarfonts的问题

来自分类Dev

更新到11.10后的链接问题

来自分类Dev

更新到2.6.3.0版后的Sourcetree问题

来自分类Dev

启用常春藤时从子级更改父级属性后,更新到Angular 9后,ExpressionChangedAfterItHaHasBeenCheckedError

来自分类Dev

Angular:从8更新到9-Hammerjs + @ angular / platform-browser停止工作

来自分类Dev

Angular:从8更新到9-Hammerjs + @ angular / platform-browser停止工作

来自分类Dev

更新到Angular 9,并且Raw-loader不再起作用

来自分类Dev

更新到Angular 1.3后,我的TypeScript类未定义

来自分类Dev

更新到最新的 Angular CLI 后,ng serve 命令不起作用

来自分类Dev

从ubuntu 10.04更新到12.04后的Grub问题

来自分类Dev

将OS X更新到El Capitan后的Mcrypt问题

来自分类Dev

Ubuntu更新到16.04版本后的登录问题

来自分类Dev

将Android Studio更新到2.0后的FragmentBuilder问题

来自分类Dev

更新到3.5.0后的Cordova构建错误

来自分类Dev

更新到5.0后的android Mediaplayer错误

来自分类常见问题

更新到3.0后Gradle构建失败

来自分类Dev

更新到XCode 5.1后出现错误

来自分类Dev

更新到4.2后withTrashed()失败

来自分类Dev

错误更新到3.6.1 Anroid的后

来自分类Dev

更新到ChromeDriver 78.0.3904.70后,InvalidArgumentException

来自分类Dev

从14.04更新到18.04后启动卡死

来自分类Dev

从19.04更新到19.10后滞后

来自分类Dev

更新到15.10后无法装入CD

Related 相关文章

  1. 1

    更新到Angular 9

  2. 2

    从Angular 8更新到Angular 9后,“ ng generate component”会生成.css文件而不是.scss

  3. 3

    更新到 angular 4 后找不到 platformUniversalDynamic

  4. 4

    更新到 Angular 8 CLI 后抛出“.getColorDepth is not a function”

  5. 5

    从V8更新到V9后,Angular App无法编译

  6. 6

    更新到Swift 3后的问题

  7. 7

    更新到XCode 6后Moarfonts的问题

  8. 8

    更新到11.10后的链接问题

  9. 9

    更新到2.6.3.0版后的Sourcetree问题

  10. 10

    启用常春藤时从子级更改父级属性后,更新到Angular 9后,ExpressionChangedAfterItHaHasBeenCheckedError

  11. 11

    Angular:从8更新到9-Hammerjs + @ angular / platform-browser停止工作

  12. 12

    Angular:从8更新到9-Hammerjs + @ angular / platform-browser停止工作

  13. 13

    更新到Angular 9,并且Raw-loader不再起作用

  14. 14

    更新到Angular 1.3后,我的TypeScript类未定义

  15. 15

    更新到最新的 Angular CLI 后,ng serve 命令不起作用

  16. 16

    从ubuntu 10.04更新到12.04后的Grub问题

  17. 17

    将OS X更新到El Capitan后的Mcrypt问题

  18. 18

    Ubuntu更新到16.04版本后的登录问题

  19. 19

    将Android Studio更新到2.0后的FragmentBuilder问题

  20. 20

    更新到3.5.0后的Cordova构建错误

  21. 21

    更新到5.0后的android Mediaplayer错误

  22. 22

    更新到3.0后Gradle构建失败

  23. 23

    更新到XCode 5.1后出现错误

  24. 24

    更新到4.2后withTrashed()失败

  25. 25

    错误更新到3.6.1 Anroid的后

  26. 26

    更新到ChromeDriver 78.0.3904.70后,InvalidArgumentException

  27. 27

    从14.04更新到18.04后启动卡死

  28. 28

    从19.04更新到19.10后滞后

  29. 29

    更新到15.10后无法装入CD

热门标签

归档