(string|number)[] 和 string[]|number[] 之间的打字稿 ngrx 类型不匹配
typescript ngrx type mismatch between (string|number)[] and string[]|number[]
我正在尝试使用以下其他库将我的 angular 应用程序升级到 5.2.10:
ngrx 5.2.0
打字稿:2.6.2
tslint 5.10.0
并在 angular 编译期间遇到以下错误:
`
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>;
}
`
有解决这些错误的建议吗?
(string|number)[]
是一个数组,可以包含字符串或数字元素
string[] | number[]
是字符串数组或数字数组。
第一个允许像 [1, "2", 3]
这样的数组,第二个不允许它们。因此,为了您的安全,编译器会抱怨。解决方案:只使用两者之一。
我正在尝试使用以下其他库将我的 angular 应用程序升级到 5.2.10: ngrx 5.2.0 打字稿:2.6.2 tslint 5.10.0
并在 angular 编译期间遇到以下错误:
`
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>;
}
`
有解决这些错误的建议吗?
(string|number)[]
是一个数组,可以包含字符串或数字元素
string[] | number[]
是字符串数组或数字数组。
第一个允许像 [1, "2", 3]
这样的数组,第二个不允许它们。因此,为了您的安全,编译器会抱怨。解决方案:只使用两者之一。