Skip to content

NonFunctionKeys

自 1.0.0 起

获取非函数属性的键。

签名

typescript
type NonFunctionKeys<T> = {
  [K in keyof T]: T[K] extends (...args: any[]) => any ? never : K
}[keyof T]

参数

参数描述
T对象类型

描述

从对象类型中提取所有非函数属性的键。

示例

基本用法

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

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

type DataKeys = NonFunctionKeys<User>
// 'name' | 'age'

只有函数

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

type NoData = NonFunctionKeys<Handlers> // never

相关

基于 MIT 许可发布