Javascript 我可以在angular+;中使用对象扩展语法吗;ngrx?

Javascript 我可以在angular+;中使用对象扩展语法吗;ngrx?,javascript,object,redux,ngrx,spread-syntax,Javascript,Object,Redux,Ngrx,Spread Syntax,我正在阅读关于对象扩展语法的文章,并试图在我的项目中使用它,我的设置如下: 角度2 angular/cli 1.0.0-rc.0 ngrx/核心1.2.0 ngrx/存储2.2.1 rxjs 5.1.0 typescript 2.0.10 在我的减速机里,我有 export interface State { [id: number]: string } export function reducer(state= {}, action: Action): State { case '

我正在阅读关于对象扩展语法的文章,并试图在我的项目中使用它,我的设置如下:

  • 角度2
  • angular/cli 1.0.0-rc.0
  • ngrx/核心1.2.0
  • ngrx/存储2.2.1
  • rxjs 5.1.0
  • typescript 2.0.10
在我的减速机里,我有

export interface State {
  [id: number]: string
}

export function reducer(state= {}, action: Action): State {
case 'TEST':
  return {
    ...state,
    2: 'foo'
  }
}
但我遇到了以下编译错误,我正试图找出问题所在:

Property assignment expected
Type '{ 2: string; state: State; }' is not assignable to type 'State'
Object literal may only specify known properties, and 'state' does not exist in type 'State'

有什么想法吗?谢谢

不适用于您正在使用的TypeScript版本

对对象属性扩展语法的支持是:

对象展开和静止 TypeScript 2.1提供了对的支持

与阵列排列类似,排列对象可以方便地获得浅拷贝:

let copy = { ...original };

伟大的非常感谢你!一般来说,我可以在angular项目中将typescript版本更新为最新版本吗?或者angular的特定版本是否需要特定版本的typescript?我不记得最近的任何typescript版本有特别的问题。我通常会尽可能地更新大部分内容,所以我已经有一段时间没有使用你在问题中提到的版本了。有一些突破性的更改,但它们已经出现在我的代码中。这里有一个关于版本、功能和更改的全面文档: