Skip to content

Latest commit

 

History

History
59 lines (41 loc) · 1.19 KB

File metadata and controls

59 lines (41 loc) · 1.19 KB

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 Target or Source is not Function, it returns never.

Type Parameters

Type Parameter Description

Target extends Fn

The target Function type.

Source extends Fn

The source Function type.

Returns

A new Function combining parameter and return types from both Target and Source.

Example

// (param_0: number, param_1: string) => { a: number; b: string }
type Result = FunctionAssign<(...param: [string, string]) => { a: string; b: string }, (...param: [number]) => { a: number }>