Skip to content

DataOnly ​

Since 1.0.0

Extract only non-function properties from an object.

Signature ​

typescript
type DataOnly<T> = Pick<T, NonFunctionKeys<T>>

Parameters ​

ParameterDescription
TThe object type

Description ​

Creates a new type containing only the non-function (data) properties of the original type.

Examples ​

Basic Usage ​

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

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

type Data = DataOnly<User>
// { name: string; age: number }

Only Functions ​

typescript
interface Handlers {
  onClick: () => void
  onChange: () => void
}

type NoData = DataOnly<Handlers> // {}

Released under the MIT License.