typelab / utils / FunctionAssign
type FunctionAssign<Target, Source> = Target extends Fn<infer TargetParams, infer TargetReturn> ? Source extends Fn<infer SourceParams, infer SourceReturn> ? (...param) => ObjectAssign<TargetReturn, SourceReturn> : never : never;Assign the parameter and return types of Source into Target.
Use `ArrayAssign` for the parameter type and `ObjectAssign` for the return type.
- If
TargetorSourceis notFunction, it returnsnever.
| Type Parameter | Description |
|---|---|
|
|
The target |
|
|
The source |
A new Function combining parameter and return types from both Target and Source.
// (param_0: number, param_1: string) => { a: number; b: string }
type Result = FunctionAssign<(...param: [string, string]) => { a: string; b: string }, (...param: [number]) => { a: number }>