@ts-type/unpacked 1.0.1 → 1.0.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.
- package/CHANGELOG.md +20 -0
- package/README.md +32 -3
- package/index.d.ts +42 -0
- package/index.js.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,26 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.0.2](https://github.com/bluelovers/ws-ts-type/compare/@ts-type/unpacked@1.0.1...@ts-type/unpacked@1.0.2) (2026-03-07)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### 📚 Documentation
|
|
11
|
+
|
|
12
|
+
* enhance documentation and JSDoc comments across multiple packages ([88ee99b](https://github.com/bluelovers/ws-ts-type/commit/88ee99b3a489645ca53093357cc3523dbe7996e0))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### 🛠 Build System
|
|
16
|
+
|
|
17
|
+
* 更新多個套件的 test 指令為 jest ([61ea53b](https://github.com/bluelovers/ws-ts-type/commit/61ea53bf15fc3ed0e216793200604ae5a52079c9))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### ♻️ Chores
|
|
21
|
+
|
|
22
|
+
* migrate from yarn to pnpm and enhance test infrastructure ([8a5daa2](https://github.com/bluelovers/ws-ts-type/commit/8a5daa2f2022eaf025c3349d4fe5dc8971f8c077))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
6
26
|
## 1.0.1 (2022-10-10)
|
|
7
27
|
|
|
8
28
|
|
package/README.md
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ts-type/unpacked
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
類型解包裝工具,從複雜類型中提取內部類型
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Type unpacking utilities to extract inner types from complex types
|
|
6
|
+
|
|
7
|
+
## 功能特點 / Features
|
|
8
|
+
|
|
9
|
+
- 從 Promise、Map、Set 等包裝類型中提取內部類型
|
|
10
|
+
- Extract inner types from Promise, Map, Set and other wrapper types
|
|
11
|
+
- 支援函式回傳類型、Iterator、ArrayLike 等
|
|
12
|
+
- Support function return types, Iterator, ArrayLike, etc.
|
|
13
|
+
- 完整的 TypeScript 類型推論
|
|
14
|
+
- Complete TypeScript type inference
|
|
15
|
+
|
|
16
|
+
## 安裝 / Install
|
|
6
17
|
|
|
7
18
|
```bash
|
|
8
19
|
yarn add @ts-type/unpacked
|
|
@@ -10,3 +21,21 @@ yarn-tool add @ts-type/unpacked
|
|
|
10
21
|
yt add @ts-type/unpacked
|
|
11
22
|
```
|
|
12
23
|
|
|
24
|
+
## 使用範例 / Usage Example
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import type { ITSUnpacked, ITSUnpackedPromiseLike, ITSUnpackedArrayLike } from '@ts-type/unpacked';
|
|
28
|
+
|
|
29
|
+
// 解包裝 Promise 類型
|
|
30
|
+
type PromiseValue = ITSUnpacked<Promise<string>>;
|
|
31
|
+
// type: string
|
|
32
|
+
|
|
33
|
+
// 解包裝陣列類型
|
|
34
|
+
type ArrayElement = ITSUnpackedArrayLike<string[]>;
|
|
35
|
+
// type: string
|
|
36
|
+
|
|
37
|
+
// 解包裝 Iterator
|
|
38
|
+
type IteratorValue = ITSUnpacked<Iterator<number>>;
|
|
39
|
+
// type: number
|
|
40
|
+
```
|
|
41
|
+
|
package/index.d.ts
CHANGED
|
@@ -1,10 +1,52 @@
|
|
|
1
1
|
import { ITSMapLike, ITSResolvable, ITSTypeFunction } from 'ts-type/lib/generic';
|
|
2
|
+
/**
|
|
3
|
+
* 取得函式回傳類型的未包裝類型
|
|
4
|
+
* Get unpacked type of function return type
|
|
5
|
+
*
|
|
6
|
+
* @typeParam T - 函式類型 / Function type
|
|
7
|
+
*/
|
|
2
8
|
export type ITSUnpackedReturnType<T extends (...args: any[]) => any> = ITSUnpacked<ReturnType<T>>;
|
|
3
9
|
/**
|
|
10
|
+
* 解包裝類型 - 從各種包裝類型中提取內部類型
|
|
11
|
+
* Unpack type - Extract inner type from various wrapper types
|
|
12
|
+
*
|
|
13
|
+
* 支援解包裝:
|
|
14
|
+
* - Map, WeakMap, Set, WeakSet 等 MapLike 類型
|
|
15
|
+
* - 陣列 / Array
|
|
16
|
+
* - ArrayLike
|
|
17
|
+
* - Iterator / IteratorResult
|
|
18
|
+
* - 函式
|
|
19
|
+
* - 可解析類型(Promise, Thenable)
|
|
20
|
+
*
|
|
4
21
|
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html
|
|
22
|
+
* @typeParam T - 要解包裝的類型 / Type to unpack
|
|
5
23
|
*/
|
|
6
24
|
export type ITSUnpacked<T> = T extends ITSMapLike<any, infer U> ? U : T extends (infer U)[] ? U : T extends ArrayLike<infer U> ? U : T extends Iterator<infer U> ? U : T extends IteratorResult<infer U> ? U : T extends ITSTypeFunction<infer U> ? U : T extends ITSResolvable<infer U> ? U : T;
|
|
25
|
+
/**
|
|
26
|
+
* 解包裝可 Promise 或 Thenable 類型
|
|
27
|
+
* Unpack Promise or Thenable type
|
|
28
|
+
*
|
|
29
|
+
* @typeParam T - 要解包裝的類型 / Type to unpack
|
|
30
|
+
*/
|
|
7
31
|
export type ITSUnpackedPromiseLike<T> = T extends ITSResolvable<infer U> ? U : T;
|
|
32
|
+
/**
|
|
33
|
+
* 解包裝 Iterator 或 IteratorResult 類型
|
|
34
|
+
* Unpack Iterator or IteratorResult type
|
|
35
|
+
*
|
|
36
|
+
* @typeParam T - Iterator 相關類型 / Iterator-related type
|
|
37
|
+
*/
|
|
8
38
|
export type ITSUnpackedIteratorLike<T extends Iterator<any> | IteratorResult<any>> = T extends Iterator<infer U> ? U : T extends IteratorYieldResult<infer U> ? U : never;
|
|
39
|
+
/**
|
|
40
|
+
* 解包裝類陣列或陣列類型
|
|
41
|
+
* Unpack array-like or array type
|
|
42
|
+
*
|
|
43
|
+
* @typeParam T - 陣列類型 / Array type
|
|
44
|
+
*/
|
|
9
45
|
export type ITSUnpackedArrayLike<T extends ArrayLike<any> | any[]> = T extends (infer U)[] ? ITSUnpacked<U> : T extends readonly (infer U)[] ? ITSUnpacked<U> : T extends ArrayLike<infer U> ? ITSUnpacked<U> : T;
|
|
46
|
+
/**
|
|
47
|
+
* 取得函式的 this 參數類型
|
|
48
|
+
* Get the this parameter type of a function
|
|
49
|
+
*
|
|
50
|
+
* @typeParam T - 函式類型 / Function type
|
|
51
|
+
*/
|
|
10
52
|
export type ITSUnpackedThisFunction<T extends (...args: any[]) => any> = T extends (this: infer R, ...args: any[]) => any ? R : unknown;
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"","sourcesContent":["import { ITSMapLike, ITSResolvable, ITSTypeFunction } from 'ts-type/lib/generic';\n\nexport type ITSUnpackedReturnType<T extends (...args: any[]) => any> =\n\tITSUnpacked<ReturnType<T>>\n//\tT extends ITSTypeFunction<infer R>\n//\t\t? ITSUnpacked<R>\n//\t\t: T\n\t;\n\n/**\n * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html\n */\nexport type ITSUnpacked<T> =\n\tT extends ITSMapLike<any, infer U> ? U :\n\t\tT extends (infer U)[] ? U :\n\t\t\tT extends ArrayLike<infer U> ? U :\n\t\t\t\tT extends Iterator<infer U> ? U :\n\t\t\t\t\tT extends IteratorResult<infer U> ? U :\n\t\t\t\t\t\tT extends ITSTypeFunction<infer U> ? U :\n\t\t\t\t\t\t\tT extends ITSResolvable<infer U> ? U :\n\t\t\t\t\t\t\t\t//T extends Promise<infer U> ? U :\n\t\t\t\t\t\t\t\tT\n\t;\n\nexport type ITSUnpackedPromiseLike<T> =\n\tT extends ITSResolvable<infer U> ? U :\n\t\tT\n\t;\n\nexport type ITSUnpackedIteratorLike<T extends Iterator<any> | IteratorResult<any>> =\n\tT extends Iterator<infer U> ? U :\n\t\tT extends IteratorYieldResult<infer U> ? U :\n\t\t\t\tnever\n\t;\n\nexport type ITSUnpackedArrayLike<T extends ArrayLike<any> | any[]> =\n\tT extends (infer U)[] ? ITSUnpacked<U> :\n\t\tT extends readonly (infer U)[] ? ITSUnpacked<U> :\n\t\t\tT extends ArrayLike<infer U> ? ITSUnpacked<U> :\n\t\t\t\tT\n\t;\n\nexport type ITSUnpackedThisFunction<T extends (...args: any[]) => any> =\n\tT extends (this: infer R, ...args: any[]) => any\n\t\t? R\n\t\t: unknown;\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"","sourcesContent":["import { ITSMapLike, ITSResolvable, ITSTypeFunction } from 'ts-type/lib/generic';\n\n/**\n * 取得函式回傳類型的未包裝類型\n * Get unpacked type of function return type\n *\n * @typeParam T - 函式類型 / Function type\n */\nexport type ITSUnpackedReturnType<T extends (...args: any[]) => any> =\n\tITSUnpacked<ReturnType<T>>\n//\tT extends ITSTypeFunction<infer R>\n//\t\t? ITSUnpacked<R>\n//\t\t: T\n\t;\n\n/**\n * 解包裝類型 - 從各種包裝類型中提取內部類型\n * Unpack type - Extract inner type from various wrapper types\n *\n * 支援解包裝:\n * - Map, WeakMap, Set, WeakSet 等 MapLike 類型\n * - 陣列 / Array\n * - ArrayLike\n * - Iterator / IteratorResult\n * - 函式\n * - 可解析類型(Promise, Thenable)\n *\n * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html\n * @typeParam T - 要解包裝的類型 / Type to unpack\n */\nexport type ITSUnpacked<T> =\n\tT extends ITSMapLike<any, infer U> ? U :\n\t\tT extends (infer U)[] ? U :\n\t\t\tT extends ArrayLike<infer U> ? U :\n\t\t\t\tT extends Iterator<infer U> ? U :\n\t\t\t\t\tT extends IteratorResult<infer U> ? U :\n\t\t\t\t\t\tT extends ITSTypeFunction<infer U> ? U :\n\t\t\t\t\t\t\tT extends ITSResolvable<infer U> ? U :\n\t\t\t\t\t\t\t\t//T extends Promise<infer U> ? U :\n\t\t\t\t\t\t\t\tT\n\t;\n\n/**\n * 解包裝可 Promise 或 Thenable 類型\n * Unpack Promise or Thenable type\n *\n * @typeParam T - 要解包裝的類型 / Type to unpack\n */\nexport type ITSUnpackedPromiseLike<T> =\n\tT extends ITSResolvable<infer U> ? U :\n\t\tT\n\t;\n\n/**\n * 解包裝 Iterator 或 IteratorResult 類型\n * Unpack Iterator or IteratorResult type\n *\n * @typeParam T - Iterator 相關類型 / Iterator-related type\n */\nexport type ITSUnpackedIteratorLike<T extends Iterator<any> | IteratorResult<any>> =\n\tT extends Iterator<infer U> ? U :\n\t\tT extends IteratorYieldResult<infer U> ? U :\n\t\t\t\tnever\n\t;\n\n/**\n * 解包裝類陣列或陣列類型\n * Unpack array-like or array type\n *\n * @typeParam T - 陣列類型 / Array type\n */\nexport type ITSUnpackedArrayLike<T extends ArrayLike<any> | any[]> =\n\tT extends (infer U)[] ? ITSUnpacked<U> :\n\t\tT extends readonly (infer U)[] ? ITSUnpacked<U> :\n\t\t\tT extends ArrayLike<infer U> ? ITSUnpacked<U> :\n\t\t\t\tT\n\t;\n\n/**\n * 取得函式的 this 參數類型\n * Get the this parameter type of a function\n *\n * @typeParam T - 函式類型 / Function type\n */\nexport type ITSUnpackedThisFunction<T extends (...args: any[]) => any> =\n\tT extends (this: infer R, ...args: any[]) => any\n\t\t? R\n\t\t: unknown;\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-type/unpacked",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "類型解包裝工具,從複雜類型中提取內部類型 | Type unpacking utilities to extract inner types from complex types",
|
|
5
5
|
"keywords": [
|
|
6
6
|
".d.ts",
|
|
7
7
|
"@types",
|
|
@@ -51,17 +51,18 @@
|
|
|
51
51
|
"pretest": "echo pretest",
|
|
52
52
|
"test": "yarn run test:tsd",
|
|
53
53
|
"test:jest": "jest --passWithNoTests",
|
|
54
|
+
"test:jest:coverage": "node --run test:jest -- --coverage",
|
|
54
55
|
"test:jest:snapshot": "yarn run test:jest -- -u",
|
|
55
56
|
"test:mocha": "ynpx --quiet -p ts-node -p mocha mocha -- --require ts-node/register \"!(node_modules)/**/*.{test,spec}.{ts,tsx}\"",
|
|
56
57
|
"test:snapshot": "yarn run test -- -u",
|
|
57
58
|
"test:tsd": "ynpx tsd -f ./test/unpacked.test-d.ts",
|
|
58
|
-
"test:tsdx": "
|
|
59
|
+
"test:tsdx": "tsdx test --passWithNoTests",
|
|
59
60
|
"build:dts:bundle": "ynpx dts-bundle-generator -o ./dist/index.d.ts ./src/index.ts --no-banner --inline-declare-global & echo build:dts:bundle",
|
|
60
61
|
"build:dts:copy": "copy .\\src\\index.d.ts .\\dist\\index.d.ts & echo build:dts",
|
|
61
62
|
"build:dts:tsc": "yarn run build:dts:tsc:emit && yarn run build:dts:copy",
|
|
62
63
|
"build:dts:tsc:emit": "tsc --emitDeclarationOnly --declaration --noEmit false",
|
|
63
64
|
"build:microbundle": "ynpx microbundle --target node",
|
|
64
|
-
"build:tsdx": "
|
|
65
|
+
"build:tsdx": "tsdx build --target node --name index",
|
|
65
66
|
"ci:install": "echo ci:install",
|
|
66
67
|
"ci:build": "echo ci:build",
|
|
67
68
|
"preversion": "echo preversion && yarn run test",
|
|
@@ -82,11 +83,10 @@
|
|
|
82
83
|
"tsc:showConfig": "ynpx get-current-tsconfig -p"
|
|
83
84
|
},
|
|
84
85
|
"dependencies": {
|
|
85
|
-
"ts-type": "^3.0.
|
|
86
|
+
"ts-type": "^3.0.2"
|
|
86
87
|
},
|
|
87
|
-
"packageManager": "yarn@1.22.19",
|
|
88
88
|
"publishConfig": {
|
|
89
89
|
"access": "public"
|
|
90
90
|
},
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "57f82cba146cfef0d0f3f138e5ec736cd17f040d"
|
|
92
92
|
}
|