/** * 创建模块接口实现方法 * * ```ts * import { createImplement } from 'sunny-js' * // 定义模块接口 * interface ModuleInterfaces { * getRole?: () => string * defaultPrivilege?: string * } * const iACL = { * defaultPrivilege: 'view', * } as ModuleInterfaces * // 创建实现接口方法 * const ACLImplement = createImplement(iACL) * // 实现接口 * ACLImplement({ * getRole() { * return 'guest' * }, * }) * ``` * * @param interfaces 默认实现。可被返回的函数修改 * @category 模块 */ export declare function createImplement>(interfaces: TObj): (userInterfaces: TObj) => TObj; /** * 调用模块接口函数,并提供备选函数 * * ```ts * // 定义模块接口 * import { invokeInterface } from 'sunny-js' * interface ModuleInterfaces { * getRole?: () => string * defaultPrivilege?: string * } * const iACL = { * defaultPrivilege: 'view', * } as ModuleInterfaces * const getRole = invokeInterface( * () => iACL.getRole, * () => 'guest' * ) * console.log(getRole()) * ``` * * @param fn 获取模块接口函数 * @param fallback 备用函数实现。默认使用{@link shouldImplement}函数 * @see {@link shouldImplement}也提供了相关用例 * @category 模块 */ export declare function invokeInterface(fn: () => (...args: TArgs) => TReturn, fallback?: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn; /** * 要求实现接口消息函数 * * ```ts * import { invokeInterface, shouldImplement } from 'sunny-js' * // 定义模块接口 * interface ModuleInterfaces { * getRole?: () => string * defaultPrivilege?: string * } * const iACL = { * defaultPrivilege: 'view', * } as ModuleInterfaces * // invokeInterface默认使用shouldImplement作为备选函数 * const getRole = invokeInterface(() => iACL.getRole) * console.log(getRole()) * // 使用shouldImplement作为备选函数,要求必须实现接口 * const getRole2 = invokeInterface( * () => iACL.getRole, * shouldImplement('iACL.getRole') * ) * console.log(getRole2()) * ``` * * @param iName 函数路径或函数引用 * @throws 直接抛出[TypeError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError)异常 * @see {@link invokeInterface} * @category 模块 */ export declare function shouldImplement(iName: string | ((...args: any[]) => any)): () => never;