Skip to content

RequireFunction

自 1.3.0 起

确保类型是函数。

签名

typescript
type RequireFunction<T> = T extends (...args: any[]) => any ? T : never

参数

参数描述
T要检查的类型

示例

基本用法

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

type Result = RequireFunction<() => void> // () => void
type Failed = RequireFunction<string> // never

带类型的函数

typescript
type Handler = (event: Event) => void
type ValidHandler = RequireFunction<Handler> // Handler

联合类型

typescript
type MaybeFunc = string | ((x: number) => number)
type OnlyFunc = RequireFunction<MaybeFunc> // (x: number) => number

相关

基于 MIT 许可发布