如何修复管道中的 Ramda drop dropLast 类型错误?
How to fix Ramda drop dropLast type error in pipe?
我在打字稿中使用 ramda 使用以下代码,它一直显示类型不匹配的错误:
R.pipe(R.drop(2), R.dropLast(5))("hello world");
TS2769: No overload matches this call. The last overload gave the following error. Argument of type '{ (xs: string): string; (xs: readonly unknown[]): unknown[]; }' is not assignable to parameter of type '(x0: readonly unknown[], x1: unknown, x2: unknown) => string'. Types of parameters 'xs' and 'x0' are incompatible. Type 'readonly unknown[]' is not assignable to type 'string'.
应该如何解决这个问题?
类型推断似乎需要一些额外的帮助,让它知道您希望将类型缩小为 string
。
例如
R.pipe<string, string, string>(R.drop(2), R.dropLast(5))("hello world")
// or
R.pipe(R.drop(2) as (str: string) => string, R.dropLast(5))("hello world")
我在打字稿中使用 ramda 使用以下代码,它一直显示类型不匹配的错误:
R.pipe(R.drop(2), R.dropLast(5))("hello world");
TS2769: No overload matches this call. The last overload gave the following error. Argument of type '{ (xs: string): string; (xs: readonly unknown[]): unknown[]; }' is not assignable to parameter of type '(x0: readonly unknown[], x1: unknown, x2: unknown) => string'. Types of parameters 'xs' and 'x0' are incompatible. Type 'readonly unknown[]' is not assignable to type 'string'.
应该如何解决这个问题?
类型推断似乎需要一些额外的帮助,让它知道您希望将类型缩小为 string
。
例如
R.pipe<string, string, string>(R.drop(2), R.dropLast(5))("hello world")
// or
R.pipe(R.drop(2) as (str: string) => string, R.dropLast(5))("hello world")