【发布时间】:2020-06-18 08:18:57
【问题描述】:
我有以下功能
function pickAndTrim <T> (keys : Array<string>, object : T ) : T {
function trim <A> (input : A) : A {
if (typeof input === "string") {
return input.trim();
}
return input;
}
let updates = R.pick(keys, object);
updates = R.map(trim, updates);
return updates;
}
注意: R 是 Ramda
它所做的是它获取一个对象,从中选择某些键(和值),然后从结果对象中修剪任何值(如果它是一个字符串)。
我得到的当前错误是:
Type 'string' is not assignable to type 'A'.
'A' could be instantiated with an arbitrary type which could be unrelated to 'string'.
我如何让 typescript 接受它肯定是一个字符串(因为我用 typeof 检查了它)
【问题讨论】:
标签: typescript