Skip to content

FunctionOnly

Since 1.0.0

Extract only function properties from an object.

Signature

typescript
type FunctionOnly<T> = Pick<T, FunctionKeys<T>>

Parameters

ParameterDescription
TThe object type

Description

Creates a new type containing only the function properties of the original type.

Examples

Basic Usage

typescript
import type { FunctionOnly } from 'uni-types'

interface User {
  name: string
  age: number
  onClick: () => void
  onChange: (value: string) => void
}

type Fns = FunctionOnly<User>
// { onClick: () => void; onChange: (value: string) => void }

No Functions

typescript
interface Data {
  name: string
  email: string
}

type NoFns = FunctionOnly<Data> // {}

Released under the MIT License.