@whitesev/utils 2.9.1 → 2.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1567,9 +1567,16 @@ declare class Utils {
1567
1567
  * fn(4,5);
1568
1568
  * > 9
1569
1569
  */
1570
- createFunction(code: string): (...args: any[]) => any;
1571
- createFunction(param: string, code: string): (...args: any[]) => any;
1572
- createFunction<A extends string[], T extends boolean>(...params: [...A, code: string, isAsync: T]): T extends true ? (...params: any[]) => Promise<any> : (...args: any[]) => any;
1570
+ createFunction<R = any>(code: string): () => R;
1571
+ createFunction<R = any>(param: string, code: string): (param: any) => R;
1572
+ createFunction<P extends string[]>(...params: [...P, code: string]): (...args: {
1573
+ [K in keyof P]: any;
1574
+ }) => any;
1575
+ createFunction<P extends string[], T extends boolean>(...params: [...P, code: string, isAsync: T]): T extends true ? (...params: {
1576
+ [K in keyof P]: any;
1577
+ }) => Promise<any> : (...args: {
1578
+ [K in keyof P]: any;
1579
+ }) => any;
1573
1580
  }
1574
1581
  declare const utils: Utils;
1575
1582
  export { utils as Utils };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@whitesev/utils",
4
- "version": "2.9.1",
4
+ "version": "2.9.2",
5
5
  "type": "module",
6
6
  "description": "一个常用的工具库",
7
7
  "main": "dist/index.cjs.js",
package/src/Utils.ts CHANGED
@@ -3799,19 +3799,21 @@ class Utils {
3799
3799
  * fn(4,5);
3800
3800
  * > 9
3801
3801
  */
3802
- createFunction(code: string): (...args: any[]) => any;
3803
- createFunction(param: string, code: string): (...args: any[]) => any;
3804
- createFunction<A extends string[], T extends boolean>(
3805
- ...params: [...A, code: string, isAsync: T]
3806
- ): T extends true ? (...params: any[]) => Promise<any> : (...args: any[]) => any;
3802
+ createFunction<R = any>(code: string): () => R;
3803
+ createFunction<R = any>(param: string, code: string): (param: any) => R;
3804
+ createFunction<P extends string[]>(...params: [...P, code: string]): (...args: { [K in keyof P]: any }) => any;
3805
+ createFunction<P extends string[], T extends boolean>(
3806
+ ...params: [...P, code: string, isAsync: T]
3807
+ ): T extends true ? (...params: { [K in keyof P]: any }) => Promise<any> : (...args: { [K in keyof P]: any }) => any;
3807
3808
  createFunction<A extends string[], T extends boolean>(
3808
3809
  ...args: [...A, code: string, isAsync?: T]
3809
3810
  ): T extends true ? (...args: any[]) => Promise<any> : (...args: any[]) => any {
3810
3811
  let isAsync: string | boolean | undefined = args[args.length - 1];
3811
- if (typeof isAsync !== "boolean") {
3812
+ if (typeof isAsync === "boolean") {
3813
+ args.splice(args.length - 1, 1);
3814
+ } else {
3812
3815
  isAsync = false;
3813
3816
  }
3814
- args.splice(args.length - 1, 1);
3815
3817
  if (isAsync) {
3816
3818
  const AsyncFunctionConstructor = Object.getPrototypeOf(async function () {}).constructor;
3817
3819
  return new AsyncFunctionConstructor(...args);