0

我正在尝试使用以下其他库将我的 Angular 应用程序升级到 5.2.10:ngrx 5.2.0 typescript: 2.6.2 tslint 5.10.0

并在角度编译期间遇到以下错误:

`

ERROR in src/app/**/xxx-state.ts(301,5): error TS2322: Type '(string | number)[]' is not assignable to type 'string[] | number[]'.
  Type '(string | number)[]' is not assignable to type 'number[]'.
    Type 'string | number' is not assignable to type 'number'.
      Type 'string' is not assignable to type 'number'.
src/app/***/xxx-state.ts(305,5): error TS2322: Type '(string | number)[]' is not assignable to type 'string[] | number[]'.
  Type '(string | number)[]' is not assignable to type 'number[]'.

`

`

error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '((searchElement: string, fromIndex?: number) => number) | ((searchElement: number, fromIndex?: nu...' has no compatible call signatures.

`

我正在使用@ngrx/entity 库从ngrx 的“module.d.ts”文件中定义的以下EntityState 接口派生我们的数据状态接口。

`

export interface EntityState<T> {
    ids: string[] | number[];
    entities: Dictionary<T>;
}

`

任何解决这些错误的指针?

4

1 回答 1

1

(string|number)[]是一个可以包含字符串或数字元素的数组

string[] | number[]是字符串数组还是数字数组。

第一个允许数组[1, "2", 3],第二个不允许它们。因此,为了您的安全,编译器会抱怨。解决方案:只使用两者之一。

于 2018-05-23T04:35:14.990 回答