如何解决管道中Ramda drop dropLast类型错误?

问题描述 投票:0回答:1

我在typecript中使用下面的代码,但它一直显示类型不匹配的错误。

R.pipe(R.drop(2), R.dropLast(5))("hello world");

TS2769: No overload matches this call.   最后一个重载出现了以下错误。     类型'{ (xs: string): string; (xs: readonly unknown[]): unknown[]; }'的参数不可分配给类型'(x0: readonly unknown[], x1: unknown, x2: unknown) => string'的参数。       参数'xs'和'x0'的类型是不兼容的。         类型'readonly unknown[]'不能分配给类型'string'。

应该如何解决这个问题?

javascript typescript pipe ramda.js drop
1个回答
1
投票

似乎类型推理需要一点额外的帮助,让它知道你想将类型缩小到一个 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")
© www.soinside.com 2019 - 2024. All rights reserved.