带有枚举类型问题的Ngrx操作

时间:2017-12-14 17:20:45

标签: typescript ngrx ngrx-store

嘿所有我试图构建动作/缩减器/等等,但我遇到了令人沮丧的TypeScript问题。我尝试使用字符串枚举作为操作类型但是它无法使用以下代码进行编译:

enter image description here

以下是代码:

{{1}}

我目前正在使用以下内容:

  • Typescript 2.6.2
  • Ngrx 4.1.1

这是一个包含已修剪问题的回购:https://github.com/cha55son/ngrx-action-type-issue

有些事情需要注意。我不想将枚举转换为字符串,因为它会导致类型缩小在switch语句中失败。此外它似乎在这里工作得很好:https://github.com/ngrx/platform/blob/master/example-app/app/core/actions/layout.ts#L3所以我假设我需要设置一些TypeScript配置。据我所知,代码应该足够了。任何帮助,将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:3)

tsconfig.json中,设置strict: true也会设置strictFunctionTypes: true,从而导致错误。明确禁用strictFunctionTypes应该清除它。 { "compilerOptions": { "sourceMap": true, "declaration": false, "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "lib": [ "es2017", "dom" ], "target": "es5", "module": "es2015", "strict": true, "strictFunctionTypes": false }, "compileOnSave": true }