Skip to content

FunctionKeys ​

自 1.0.0 起

获取函数属性的键。

签名 ​

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

参数 ​

参数描述
T对象类型

描述 ​

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

示例 ​

基本用法 ​

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

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

type FnKeys = FunctionKeys<User>
// 'onClick' | 'onChange'

没有函数 ​

typescript
interface Data {
  name: string
  email: string
}

type NoFns = FunctionKeys<Data> // never

相关 ​

基于 MIT 许可发布