@loickit/shared 0.0.6 → 0.0.8
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.
- package/dist/typeTool.d.mts +31 -0
- package/dist/typeTool.d.ts +31 -0
- package/dist/typeTool.mjs +1 -0
- package/package.json +9 -5
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取函数的参数类型元组
|
|
3
|
+
* @example
|
|
4
|
+
* type Fn = (a: number, b: string) => void
|
|
5
|
+
* type Params = FunctionParams<Fn> // [number, string]
|
|
6
|
+
*/
|
|
7
|
+
type FunctionParams<T extends (...args: any[]) => any> = T extends (...args: infer P) => any ? P : never;
|
|
8
|
+
/**
|
|
9
|
+
* 获取函数指定位置的参数类型
|
|
10
|
+
* @example
|
|
11
|
+
* type Fn = (a: number, b: string) => void
|
|
12
|
+
* type FirstParam = FunctionParam<Fn, 0> // number
|
|
13
|
+
* type SecondParam = FunctionParam<Fn, 1> // string
|
|
14
|
+
*/
|
|
15
|
+
type FunctionParam<T extends (...args: any[]) => any, N extends number> = FunctionParams<T>[N] extends infer P ? P : never;
|
|
16
|
+
/**
|
|
17
|
+
* 获取函数的第一个参数类型
|
|
18
|
+
* @example
|
|
19
|
+
* type Fn = (a: number, b: string) => void
|
|
20
|
+
* type First = FirstFunctionParam<Fn> // number
|
|
21
|
+
*/
|
|
22
|
+
type FunctionFirstParam<T extends (...args: any[]) => any> = FunctionParam<T, 0>;
|
|
23
|
+
/**
|
|
24
|
+
* 获取函数的最后一个参数类型
|
|
25
|
+
* @example
|
|
26
|
+
* type Fn = (a: number, b: string, c: boolean) => void
|
|
27
|
+
* type Last = LastFunctionParam<Fn> // boolean
|
|
28
|
+
*/
|
|
29
|
+
type FunctionLastParam<T extends (...args: any[]) => any> = FunctionParams<T> extends [...infer _, infer Last] ? Last : never;
|
|
30
|
+
|
|
31
|
+
export type { FunctionFirstParam, FunctionLastParam, FunctionParam, FunctionParams };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取函数的参数类型元组
|
|
3
|
+
* @example
|
|
4
|
+
* type Fn = (a: number, b: string) => void
|
|
5
|
+
* type Params = FunctionParams<Fn> // [number, string]
|
|
6
|
+
*/
|
|
7
|
+
type FunctionParams<T extends (...args: any[]) => any> = T extends (...args: infer P) => any ? P : never;
|
|
8
|
+
/**
|
|
9
|
+
* 获取函数指定位置的参数类型
|
|
10
|
+
* @example
|
|
11
|
+
* type Fn = (a: number, b: string) => void
|
|
12
|
+
* type FirstParam = FunctionParam<Fn, 0> // number
|
|
13
|
+
* type SecondParam = FunctionParam<Fn, 1> // string
|
|
14
|
+
*/
|
|
15
|
+
type FunctionParam<T extends (...args: any[]) => any, N extends number> = FunctionParams<T>[N] extends infer P ? P : never;
|
|
16
|
+
/**
|
|
17
|
+
* 获取函数的第一个参数类型
|
|
18
|
+
* @example
|
|
19
|
+
* type Fn = (a: number, b: string) => void
|
|
20
|
+
* type First = FirstFunctionParam<Fn> // number
|
|
21
|
+
*/
|
|
22
|
+
type FunctionFirstParam<T extends (...args: any[]) => any> = FunctionParam<T, 0>;
|
|
23
|
+
/**
|
|
24
|
+
* 获取函数的最后一个参数类型
|
|
25
|
+
* @example
|
|
26
|
+
* type Fn = (a: number, b: string, c: boolean) => void
|
|
27
|
+
* type Last = LastFunctionParam<Fn> // boolean
|
|
28
|
+
*/
|
|
29
|
+
type FunctionLastParam<T extends (...args: any[]) => any> = FunctionParams<T> extends [...infer _, infer Last] ? Last : never;
|
|
30
|
+
|
|
31
|
+
export type { FunctionFirstParam, FunctionLastParam, FunctionParam, FunctionParams };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/package.json
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loickit/shared",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "loickit shared lib",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"import": "./dist/index.mjs",
|
|
9
9
|
"types": "./dist/index.d.ts"
|
|
10
|
+
},
|
|
11
|
+
"./typeTools": {
|
|
12
|
+
"types": "./dist/typeTool.d.ts",
|
|
13
|
+
"import": "./dist/typeTool.d.ts"
|
|
10
14
|
}
|
|
11
15
|
},
|
|
12
16
|
"files": [
|
|
13
17
|
"dist"
|
|
14
18
|
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "loickit-cli build:lib"
|
|
21
|
+
},
|
|
15
22
|
"keywords": [
|
|
16
23
|
"loickit"
|
|
17
24
|
],
|
|
@@ -20,8 +27,5 @@
|
|
|
20
27
|
"access": "public"
|
|
21
28
|
},
|
|
22
29
|
"license": "UNLICENSED",
|
|
23
|
-
"author": "licheung228"
|
|
24
|
-
"scripts": {
|
|
25
|
-
"build": "loickit-cli build:lib"
|
|
26
|
-
}
|
|
30
|
+
"author": "licheung228"
|
|
27
31
|
}
|