考虑以下代码:
const selectFrom =
<T>() =>
<U extends Partial<T>>(fields: U) => {
return fields as U;
};
type Item = { a: string; b: string };
// intellisense on the argument Partial<Item>
const x = selectFrom<Item>()({ a: "" });
// typeof x => { a: string }
Run Code Online (Sandbox Code Playgroud)
selectFrom仅当返回另一个函数时,我才能获得我想要的类型。有没有办法实现以下目标签名?
// target signature:
const x = selectFrom<Item>({ a: "" });
// current signature:
const x = selectFrom<Item>()({ a: "" });
Run Code Online (Sandbox Code Playgroud)