FirstParameter
Since 1.0.0
Get the first parameter type of a function.
Signature
typescript
type FirstParameter<T> = T extends (first: infer F, ...rest: any[]) => any ? F : neverParameters
| Parameter | Description |
|---|---|
T | The function type |
Description
Extracts the type of the first parameter from a function type.
Examples
Basic Usage
typescript
import type { FirstParameter } from 'uni-types'
type Param = FirstParameter<(first: string, second: number) => void>
// stringSingle Parameter
typescript
type SingleParam = FirstParameter<(value: number) => void>
// numberNo Parameters
typescript
type NoParam = FirstParameter<() => void> // neverWith Object Parameter
typescript
type ObjParam = FirstParameter<(options: { a: string; b: number }) => void>
// { a: string; b: number }Related
FunctionKeys- Get function property keysFunctionOnly- Extract function properties