import { AnyFunction } from "./global.js"; //#region src/types/function.d.ts /** * 获取函数的参数类型 * @public */ type ParameterType = Func extends ((...args: infer Args) => unknown) ? Args : never; /** * 获取函数this的类型 * @public */ type ThisParameterType = Func extends ((this: infer ThisType, ...args: unknown[]) => unknown) ? ThisType : unknown; /** * 给函数添加参数 * @template Func - 原函数类型 * @template Arg - 要添加的参数类型 * @example * ```ts * type Fn = (a: string) => number * type NewFn = AppendArgument // (a: string, b: boolean) => number * ``` * @public */ type AppendArgument = Func extends ((...args: infer Args) => infer ReturnType) ? (...args: [...Args, Arg]) => ReturnType : never; /** * @public */ type PromiseFunction = (...args: Args) => Promise; /** * 获取Promise函数的返回值类型 * @public */ type PromiseReturnType = Func extends ((...args: any) => Promise) ? R : never; /** * 获取Promise函数的参数类型 * @public */ type PromiseParameterType = Func extends ((...args: infer Args) => Promise) ? Args : never; //#endregion export { AppendArgument, ParameterType, PromiseFunction, PromiseParameterType, PromiseReturnType, ThisParameterType };