我想替换函数中最后一个参数的类型,同时保留所有函数参数的名称。就我而言,最后一个参数也是可选的。
例如:
type OrigArg = { arg: number };
type ReplacedArg = { arg: string };
type OrigFunc = (a: number, b: string, c?: OrigArg) => string
type ReplaceLast<TFunc, TReplace> = // type I'm looking for
type ReplacedFunc = ReplaceLast<OrigFunc, ReplacedArg>
// type ReplacedFunc = (a: number, b: string, c?: ReplacedArg) => string
Run Code Online (Sandbox Code Playgroud)
更复杂的是前面的参数的数量和类型是可变的,我只知道最后一个参数将是某种类型,我想用自定义的类型替换它。