AnyFunction()
type AnyFunction = (...args) => any;
Defined in: types/AnyFunction.ts:20
通用函数类型,可接受任意参数并返回任意类型 用于需要表示各种函数类型的场景,提供最大的灵活性
Parameters
| Parameter | Type |
|---|---|
...args | any[] |
Returns
any
Examples
// 匹配无参数函数
const func1: AnyFunction = () => 'hello';
// 匹配带参数函数
const func2: AnyFunction = (a: number, b: string) => a + b;
// 匹配异步函数
const func3: AnyFunction = async () => { await Promise.resolve(); return 42; };
**Note:** 此类型提供了最大的灵活性,但牺牲了类型安全性
**Note:** 对于需要类型安全的场景,建议使用更具体的函数类型