[英]How to fix Ramda drop dropLast type error in pipe?
I am using below code using ramda in typescript and it keeps showing error that type is not matching:我在 typescript 中使用 ramda 使用下面的代码,它一直显示类型不匹配的错误:
R.pipe(R.drop(2), R.dropLast(5))("hello world");
TS2769: No overload matches this call.
TS2769:没有重载匹配此调用。 The last overload gave the following error.
最后一个重载给出了以下错误。 Argument of type '{ (xs: string): string;
'{ (xs: string): string; 类型的参数(xs: readonly unknown[]): unknown[];
(xs: 只读未知[]): 未知[]; }' is not assignable to parameter of type '(x0: readonly unknown[], x1: unknown, x2: unknown) => string'.
}' 不可分配给类型为 '(x0: readonly unknown[], x1: unknown, x2: unknown) => string' 的参数。 Types of parameters 'xs' and 'x0' are incompatible.
参数“xs”和“x0”的类型不兼容。 Type 'readonly unknown[]' is not assignable to type 'string'.
类型 'readonly unknown[]' 不可分配给类型 'string'。
How should fix this?应该如何解决这个问题?
It seems the type inference needs a bit of extra help to let it know that you want the type narrowed to a string
.似乎类型推断需要一些额外的帮助才能让它知道您希望将类型缩小为
string
。
eg例如
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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.