ts-type 3.0.13 → 3.0.14
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 +25 -0
- package/lib/_build-in.js.map +1 -1
- package/lib/generic.js.map +1 -1
- package/lib/helper/array/readonly.js.map +1 -1
- package/lib/helper/conditional.js.map +1 -1
- package/lib/helper/deep-map.js.map +1 -1
- package/lib/helper/filter.js.map +1 -1
- package/lib/helper/infer.js.map +1 -1
- package/lib/helper/intersection.js.map +1 -1
- package/lib/helper/key-value.d.ts +42 -5
- package/lib/helper/key-value.js.map +1 -1
- package/lib/helper/number.js.map +1 -1
- package/lib/helper/readonly.js.map +1 -1
- package/lib/helper/record/enum.js.map +1 -1
- package/lib/helper/record/member.js.map +1 -1
- package/lib/helper/record/omit-index.js.map +1 -1
- package/lib/helper/record/partial.js.map +1 -1
- package/lib/helper/record/pick-type.js.map +1 -1
- package/lib/helper/record.js.map +1 -1
- package/lib/helper/string/infer.js.map +1 -1
- package/lib/helper/string/literal-string.js.map +1 -1
- package/lib/helper/string/operations.js.map +1 -1
- package/lib/helper/string.js.map +1 -1
- package/lib/helper/tuple.js.map +1 -1
- package/lib/helper/typeof.js.map +1 -1
- package/lib/helper.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/internal/filter.js.map +1 -1
- package/lib/internal/logic/string-literal.js.map +1 -1
- package/lib/logic/any.js.map +1 -1
- package/lib/logic/never.js.map +1 -1
- package/lib/logic/record/empty.js.map +1 -1
- package/lib/logic/union/index.js.map +1 -1
- package/lib/type/base.js.map +1 -1
- package/lib/type/generator.js.map +1 -1
- package/lib/type/iterator.js.map +1 -1
- package/lib/type/promise.js.map +1 -1
- package/lib/type/proxy.js.map +1 -1
- package/lib/type/record/empty.js.map +1 -1
- package/lib/type/record/enum.js.map +1 -1
- package/lib/type/record/partial.js.map +1 -1
- package/lib/type/record/readonly.js.map +1 -1
- package/lib/type/record/union.d.ts +135 -0
- package/lib/type/record/union.js +27 -0
- package/lib/type/record/union.js.map +1 -0
- package/lib/type/record.d.ts +32 -24
- package/lib/type/record.js.map +1 -1
- package/lib/type/tuple/empty.js.map +1 -1
- package/package.json +13 -10
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,31 @@
|
|
|
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
|
+
## [3.0.14](https://github.com/bluelovers/ws-ts-type/compare/ts-type@3.0.13...ts-type@3.0.14) (2026-09-25)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### 🐛 Bug Fixes
|
|
11
|
+
|
|
12
|
+
* **ts-type:** 修復聯集類型扁平化後的屬性映射邏輯 ([201f812](https://github.com/bluelovers/ws-ts-type/commit/201f8120c8ce21a1655b805fd809e2bdb5120ce3))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### ✨ Features
|
|
16
|
+
|
|
17
|
+
* **ts-type:** 新增針對聯集類型的 Record 操作工具 ([cfc6f73](https://github.com/bluelovers/ws-ts-type/commit/cfc6f7328b910281a245a66a8205a454d30cf521))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### 📦 Code Refactoring
|
|
21
|
+
|
|
22
|
+
* **ts-type:** 優化類型定義結構與清理註解格式 ([d83912f](https://github.com/bluelovers/ws-ts-type/commit/d83912fcc7bd313f7af39140e8d70a951bcb8051))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### ♻️ Chores
|
|
26
|
+
|
|
27
|
+
* **build:** 將專案腳本從 yarn 遷移至 pnpm ([7e4ef6b](https://github.com/bluelovers/ws-ts-type/commit/7e4ef6b601bdc50a6202ecf0cad90dc91b0902d6))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
6
31
|
## [3.0.13](https://github.com/bluelovers/ws-ts-type/compare/ts-type@3.0.12...ts-type@3.0.13) (2026-03-31)
|
|
7
32
|
|
|
8
33
|
|
package/lib/_build-in.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_build-in.js","sourceRoot":"","sources":["_build-in.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * Created by user on 2019/6/11.\n
|
|
1
|
+
{"version":3,"file":"_build-in.js","sourceRoot":"","sources":["_build-in.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * Created by user on 2019/6/11.\n *\n * 重新導出內建類型\n * Re-export built-in types\n *\n * 在某些情況下 IDE 無法正確識別類型,此文件提供統一的類別導出\n * In some cases IDE cannot correctly identify types, this file provides unified type exports\n */\n\n/**\n * 取得函數的參數類型\n * Get the parameter types of a function\n *\n * @example\n * function greet(name: string, age: number): string {\n * return `Hello, ${name}, you are ${age} years old.`;\n * }\n * type Params = ITSParameters<typeof greet>;\n * // type Params = [name: string, age: number]\n *\n * @see Parameters\n */\nexport type ITSParameters<T extends (...args: any[]) => any> = Parameters<T>\n/**\n * 取得建構函數的參數類型\n * Get the constructor parameter types\n *\n * @example\n * class User {\n * constructor(public name: string, public age: number) {}\n * }\n * type CtorParams = ITSConstructorParameters<typeof User>;\n * // type CtorParams = [name: string, age: number]\n *\n * @see ConstructorParameters\n */\nexport type ITSConstructorParameters<T extends new (...args: any[]) => any> = ConstructorParameters<T>\n/**\n * 將類型的所有屬性設為可選\n * Make all properties of T optional\n *\n * @example\n * interface User { name: string; age: number; }\n * type PartialUser = ITSPartial<User>;\n * // type PartialUser = { name?: string; age?: number; }\n *\n * @see Partial\n */\nexport type ITSPartial<T> = Partial<T>\n/**\n * 從類型 T 中選取指定的屬性 K\n * Pick a set of properties K from T\n *\n * @example\n * interface User { name: string; age: number; email: string; }\n * type PickedUser = ITSPick<User, 'name' | 'age'>;\n * // type PickedUser = { name: string; age: number; }\n *\n * @see Pick\n */\nexport type ITSPick<T, K extends keyof T = keyof T> = Pick<T, K>\n/**\n * 取得建構函數實例的類型\n * Get the instance type created by a constructor\n *\n * @example\n * class User { name: string; }\n * type UserInstance = ITSInstanceType<typeof User>;\n * // type UserInstance = User\n *\n * @see InstanceType\n */\nexport type ITSInstanceType<T extends new (...args: any[]) => any> = InstanceType<T>\n\n/**\n * 類別裝飾器類型\n * Class decorator type\n *\n * @example\n * const myClassDecorator: ITSClassDecorator = (target) => {\n * console.log(`Decorating ${target.name}`);\n * return target;\n * };\n *\n * @decorator\n */\nexport type ITSClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void;\n/**\n * 屬性裝飾器類型\n * Property decorator type\n *\n * @example\n * const myPropertyDecorator: ITSPropertyDecorator = (target, propertyKey) => {\n * console.log(`Decorating property ${String(propertyKey)} on`, target);\n * };\n *\n * @decorator\n */\nexport type ITSPropertyDecorator = (target: object, propertyKey: string | symbol) => void;\n/**\n * 方法裝飾器類型\n * Method decorator type\n *\n * @example\n * const myMethodDecorator: ITSMethodDecorator = (target, propertyKey, descriptor) => {\n * console.log(`Decorating method ${String(propertyKey)}`);\n * return descriptor;\n * };\n *\n * @decorator\n */\nexport type ITSMethodDecorator = <T>(target: object,\n\tpropertyKey: string | symbol,\n\tdescriptor: TypedPropertyDescriptor<T>,\n) => TypedPropertyDescriptor<T> | void;\n/**\n * 參數裝飾器類型\n * Parameter decorator type\n *\n * @example\n * const myParameterDecorator: ITSParameterDecorator = (target, propertyKey, parameterIndex) => {\n * console.log(`Decorating parameter ${parameterIndex} of ${String(propertyKey)}`);\n * };\n *\n * @decorator\n */\nexport type ITSParameterDecorator = (target: object, propertyKey: string | symbol, parameterIndex: number) => void;\n\n/**\n * 從 T 中排除 null 和 undefined\n * Exclude null and undefined from T\n *\n * @example\n * type Test = string | number | null | undefined;\n * type NonNull = ITSNonNullable<Test>;\n * // type NonNull = string | number\n *\n * @see NonNullable\n * @see https://devblogs.microsoft.com/typescript/announcing-typescript-4-8/#improved-intersection-reduction-union-compatibility-and-narrowing\n */\nexport type ITSNonNullable<T> = NonNullable<T>;\n"]}
|
package/lib/generic.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic.js","sourceRoot":"","sources":["generic.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * 類型函數:返回指定類型的函數\n * Type function: a function that returns the specified type\n
|
|
1
|
+
{"version":3,"file":"generic.js","sourceRoot":"","sources":["generic.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * 類型函數:返回指定類型的函數\n * Type function: a function that returns the specified type\n *\n * @example\n * type StringFunc = ITSTypeFunction<string>;\n * // type StringFunc = (...args: any[]) => string\n *\n * @example\n * type NumberFunc = ITSTypeFunction<number>;\n * // type NumberFunc = (...args: any[]) => number\n */\nexport type ITSTypeFunction<T> = (...args: any[]) => T;\n\n/**\n * 類似 Map 的介面定義\n * Map-like interface definition\n */\nexport interface ITSMapLike<K, V>\n{\n\t/**\n\t * 取得指定鍵的值\n\t * Get the value for the specified key\n\t */\n\tget(key: K): V | undefined;\n\n\t/**\n\t * 檢查是否包含指定鍵\n\t * Check if the map contains the specified key\n\t */\n\thas(key: K): boolean;\n}\n\n/**\n * 類似 Set 的介面定義\n * Set-like interface definition\n */\nexport interface ITSSetLike<V>\n{\n\t/**\n\t * 檢查是否包含指定值\n\t * Check if the set contains the specified value\n\t */\n\thas(value: V): boolean;\n}\n\n/**\n * 可解析的類型:支援直接值或 PromiseLike\n * Resolvable type: supports direct value or PromiseLike\n *\n * @see bluebird\n */\nexport type ITSResolvable<R> = R | PromiseLike<R>;\n\n/**\n * 可寫入的類陣列介面\n * Writable array-like interface\n */\nexport interface ITSArrayLikeWriteable<T>\n{\n\t/** 只讀的長度屬性 / Readonly length property */\n\treadonly length: number;\n\n\t/** 數字索引存取 / Numeric index access */\n\t[n: number]: T;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readonly.js","sourceRoot":"","sources":["readonly.ts"],"names":[],"mappings":"","sourcesContent":["import { ITSArrayListMaybeReadonly } from '../../type/base';\n\n/**\n * 將可讀寫陣列轉換為唯讀陣列\n * Convert writable array to readonly array\n
|
|
1
|
+
{"version":3,"file":"readonly.js","sourceRoot":"","sources":["readonly.ts"],"names":[],"mappings":"","sourcesContent":["import { ITSArrayListMaybeReadonly } from '../../type/base';\n\n/**\n * 將可讀寫陣列轉換為唯讀陣列\n * Convert writable array to readonly array\n *\n * @example\n * type Writable = [1, 2, 3];\n * type Readonly = ITSToReadonlyArray<Writable>; // readonly [1, 2, 3]\n */\nexport type ITSToReadonlyArray<T extends ITSArrayListMaybeReadonly<any>> = T extends [...infer R] | readonly [...infer R]\n\t? readonly [...R]\n\t: never\n\t;\n\n/**\n * 將唯讀陣列轉換為可讀寫陣列\n * Convert readonly array to writable array\n *\n * @example\n * type Readonly = readonly [1, 2, 3];\n * type Writable = ITSToWriteableArray<Readonly>; // [1, 2, 3]\n */\nexport type ITSToWriteableArray<T extends ITSArrayListMaybeReadonly<any>> = T extends [...infer R] | readonly [...infer R]\n\t? [...R]\n\t: never\n\t;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditional.js","sourceRoot":"","sources":["conditional.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 條件類型工具\n * Conditional Type Utilities\n
|
|
1
|
+
{"version":3,"file":"conditional.js","sourceRoot":"","sources":["conditional.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 條件類型工具\n * Conditional Type Utilities\n *\n * 提供基於條件的類型選擇工具\n * Provides conditional-based type selection utilities\n */\n\n/**\n * 條件類型:根據條件 C 選擇 T 或 U\n * Conditional type: select T or U based on condition C\n *\n * @example\n * type IsString<T> = T extends string ? true : false;\n * type Result = ITSIf<IsString<T>, 'is string', 'not string'>;\n */\nexport type ITSHelperIf<C extends boolean, T, U> = C extends true ? T : U;\n\n/**\n * 條件類型:根據類型匹配選擇 T 或 U\n * Conditional type: select T or U based on type match\n *\n * @example\n * type Result = ITSIfExtends<string, 'text', 'other'>; // 'text'\n * type Result2 = ITSIfExtends<number, 'text', 'other'>; // 'other'\n */\nexport type ITSHelperIfExtends<T, U, IfTrue, IfFalse> = T extends U ? IfTrue : IfFalse;\n\n/**\n * 條件類型:根據類型相等選擇 T 或 U\n * Conditional type: select T or U based on type equality\n *\n * @example\n * type Result = ITSIfEquals<string, string, 'same', 'different'>; // 'same'\n * type Result2 = ITSIfEquals<string, number, 'same', 'different'>; // 'different'\n */\nexport type ITSHelperIfEquals<T, U, IfTrue, IfFalse> = T extends U\n\t? U extends T\n\t\t? IfTrue\n\t\t: IfFalse\n\t: IfFalse;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deep-map.js","sourceRoot":"","sources":["deep-map.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 深層映射工具\n * Deep Mapping Utilities\n
|
|
1
|
+
{"version":3,"file":"deep-map.js","sourceRoot":"","sources":["deep-map.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 深層映射工具\n * Deep Mapping Utilities\n *\n * 提供對物件進行深層類型轉換的工具\n * Provides utilities for deep type transformation of objects\n */\n\nimport { ITSArrayListMaybeReadonly } from '../type/base';\n\n/**\n * 深層映射:對物件的所有屬性應用轉換 - 無法實現\n * Deep mapping: apply transformation to all properties of an object\n *\n * TypeScript 無法在類型層級將函數作為泛型參數傳遞\n * TypeScript cannot pass functions as generic parameters at type level\n *\n * @example\n * interface User { name: string; profile: { age: number; } }\n * type ReadonlyUser = ITSDeepMap<User, readonly>;\n * // { readonly name: string; readonly profile: { readonly age: number; } }\n */\n// export type ITSDeepMap<T, F> = never;\n\n// 保留原始實現作為參考 / Keep original implementation for reference\n// export type ITSDeepMap<T, F> = T extends object \n// \t? T extends ITSArrayListMaybeReadonly<any>\n// \t\t? T\n// \t\t: {\n// \t\t\t[K in keyof T]: ITSDeepMap<T[K], F>;\n// \t\t }\n// \t: T;\n\n/**\n * 深層映射:對物件的所有屬性應用轉換(包含陣列)- 無法實現\n * Deep mapping: apply transformation to all properties of an object (including arrays)\n *\n * TypeScript 無法在類型層級將函數作為泛型參數傳遞\n * TypeScript cannot pass functions as generic parameters at type level\n *\n * @example\n * interface Data { items: string[]; nested: { values: number[]; } }\n * type ReadonlyData = ITSDeepMapWithArrays<Data, readonly>;\n * // { readonly items: readonly string[]; readonly nested: { readonly values: readonly number[]; } }\n */\n// export type ITSDeepMapWithArrays<T, F> = never;\n\n// 保留原始實現作為參考 / Keep original implementation for reference\n// export type ITSDeepMapWithArrays<T, F extends (x: any) => any> = T extends object \n// \t? T extends ITSArrayListMaybeReadonly<any>\n// \t\t? F<T>\n// \t\t: {\n// \t\t\t[K in keyof T]: ITSDeepMapWithArrays<T[K], F>;\n// \t\t }\n// \t: T;\n\n/**\n * 深層部分映射:對物件的所有屬性應用 Partial\n * Deep partial mapping: apply Partial to all properties of an object\n *\n * @example\n * interface User { name: string; profile: { age: number; } }\n * type PartialUser = ITSDeepPartial<User>;\n * // { name?: string; profile?: { age?: number; } }\n */\nexport type ITSDeepPartial<T> = T extends object\n\t? T extends ITSArrayListMaybeReadonly<any>\n\t\t? T\n\t\t: {\n\t\t\t[K in keyof T]?: ITSDeepPartial<T[K]>;\n\t\t}\n\t: T;\n\n/**\n * 深層必填映射:對物件的所有屬性應用 Required\n * Deep required mapping: apply Required to all properties of an object\n *\n * @example\n * interface User { name?: string; profile?: { age?: number; } }\n * type RequiredUser = ITSDeepRequired<User>;\n * // { name: string; profile: { age: number; } }\n */\nexport type ITSDeepRequired<T> = T extends object\n\t? T extends ITSArrayListMaybeReadonly<any>\n\t\t? T\n\t\t: {\n\t\t\t[K in keyof T]-?: ITSDeepRequired<T[K]>;\n\t\t}\n\t: T;\n"]}
|
package/lib/helper/filter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sourceRoot":"","sources":["filter.ts"],"names":[],"mappings":";AAAA;;GAEG","sourcesContent":["/**\n * Created by user on 2019/6/8.\n */\n\n/**\n * 從 T 中排除可指派給 U 的類型,並替換為 R\n * Exclude from T those types that are assignable to U, and replace to R\n
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["filter.ts"],"names":[],"mappings":";AAAA;;GAEG","sourcesContent":["/**\n * Created by user on 2019/6/8.\n */\n\n/**\n * 從 T 中排除可指派給 U 的類型,並替換為 R\n * Exclude from T those types that are assignable to U, and replace to R\n *\n * @example\n * type Test = string | number | boolean;\n * type Result = ITSExclude2<Test, string, never>; // number | boolean\n */\nexport type ITSExclude2<T, U, R = T> = T extends U ? never : R;\n\n/**\n * 從 T 中提取可指派給 U 的類型,並替換為 R\n * Extract from T those types that are assignable to U, and replace to R\n *\n * @example\n * type Test = string | number | boolean;\n * type Result = ITSExtract2<Test, string, 'text'>; // 'text' | number | boolean\n */\nexport type ITSExtract2<T, U, R = T> = T extends U ? R : never;\n\n/**\n * 提取 T 中屬於 U 的鍵\n * Extract keys from T that belong to U\n */\nexport type ITSExtractKeyof<T, U> = Extract<keyof T, U>;\n\n/**\n * 從類陣列類型中提取指定索引的類型\n * Extract types of specified indexes from array-like type\n *\n * @example\n * type Test = [string, number, boolean];\n * type Result = ITSExtractArrayLike<Test, 0 | 2>; // [string, boolean]\n */\nexport type ITSExtractArrayLike<A, K extends Extract<keyof A, number> = Extract<keyof A, number>> = {\n\t[Index in K]: A[Index];\n};\n\n/**\n * 取得類陣列類型的所有數字索引鍵\n * Get all numeric index keys of array-like type\n */\nexport type ITSKeyofArrayLike<A> = keyof ITSExtractArrayLike<A>;\n\n/**\n * 取得可為 null 或 undefined 的類型\n * Get types that can be null or undefined\n *\n * @example\n * type Test = string | number | null;\n * type Result = ITSNullable<Test>; // string | number | null\n */\nexport type ITSNullable<T> = T extends null | undefined ? T : never;\n\n/**\n * 找出 T 當中與 U 相同的鍵\n * Find keys that are the same between T and U\n *\n * @example\n * type A = { a: 1; b: 2; };\n * type B = { a: 3; c: 4; };\n * type Result = ITSKeyofSame<A, B>; // 'a'\n */\nexport type ITSKeyofSame<T, U> = Extract<keyof T, keyof U>;\n/**\n * 找出 T 當中與 U 不同的鍵\n * Find keys that are different between T and U\n *\n * @example\n * type A = { a: 1; b: 2; };\n * type B = { a: 3; c: 4; };\n * type Result = ITSKeyofDiff<A, B>; // 'b'\n */\nexport type ITSKeyofDiff<T, U> = Exclude<keyof T, ITSKeyofSame<T, U>>;\n\n/**\n * 找出 T 與 U 當中同時存在的鍵\n * Find keys that exist in both T and U\n *\n * @example\n * type A = { a: 1; b: 2; };\n * type B = { a: 3; c: 4; };\n * type Result = ITSKeyofBothSame<A, B>; // 'a'\n */\nexport type ITSKeyofBothSame<T, U> = ITSKeyofSame<T, U> | ITSKeyofSame<U, T>;\n\n/**\n * 去除 T 與 U 當中同時存在的鍵\n * Remove keys that exist in both T and U\n *\n * @example\n * type A = { a: 1; b: 2; };\n * type B = { a: 3; c: 4; };\n * type Result = ITSKeyofBothDiff<A, B>; // 'b' | 'c'\n */\nexport type ITSKeyofBothDiff<T, U> = ITSKeyofDiff<T, U> | ITSKeyofDiff<U, T>;\n\n/**\n * ITSFilterKeysString - 基礎鍵過濾類型\n * 從聯合類型中排除指定的字符串鍵\n *\n * 使用範例:\n * @example\n * type AllKeys = 'log' | 'debug' | 'constructor' | 'error';\n * type PublicKeys = ITSFilterKeysString<AllKeys, 'constructor'>; // 'log' | 'debug' | 'error'\n * type SafeKeys = ITSFilterKeysString<AllKeys, 'constructor' | 'error'>; // 'log' | 'debug'\n *\n * @example\n * type ITSFilterKeysString<T, ExcludeKeys extends string = never> = T extends infer U\n * \t? U extends string\n * \t\t? U extends ExcludeKeys ? never : U\n * \t\t: never\n * \t: never;\n *\n * @see ITSExcludeFilterKeys\n */\nexport type ITSExcludeFilterKeysString<T, ExcludeKeys extends string = never> = ITSExcludeFilterKeys<T, ExcludeKeys, string>;\n\n/**\n * ITSFilterKeysPropertyKey - 支持 PropertyKey(string | number | symbol)的版本\n *\n * 使用範例:\n * @example\n * type AllKeys = 'log' | 'debug' | 'constructor' | 42 | symbol;\n * type StringKeys = ITSFilterKeysPropertyKey<AllKeys, number | symbol>; // 'log' | 'debug' | 'constructor'\n * type NoSymbol = ITSFilterKeysPropertyKey<AllKeys, symbol>; // 'log' | 'debug' | 'constructor' | 42\n *\n * @example\n * type ITSFilterKeysPropertyKey<T, ExcludeKeys extends PropertyKey = never> = T extends infer U\n * \t? U extends PropertyKey\n * \t\t? U extends ExcludeKeys ? never : U\n * \t\t: never\n * \t: never;\n *\n * @see ITSExcludeFilterKeys\n */\nexport type ITSExcludeFilterKeysPropertyKey<T, ExcludeKeys extends PropertyKey = never> = ITSExcludeFilterKeys<T, ExcludeKeys, PropertyKey>;\n\n/**\n * ITSFilterKeys - 可配置鍵類型範圍的版本\n * 第三個類型參數 `AllowedPropertyKey` 允許精確控制保留哪些類型的鍵\n *\n * 使用範例:\n * @example\n * ```\n * type AllKeys = 'log' | 'debug' | 42 | 99 | symbol;\n *\n * // 只保留 string 類型,排除 'log'\n * type StringOnly = ITSFilterKeys<AllKeys, 'log', string>; // 'debug'\n *\n * // 只保留 number 類型,不排除任何鍵\n * type NumOnly = ITSFilterKeys<AllKeys, never, number>; // 42 | 99\n *\n * // 保留 string | number,排除 'debug'\n * type Mixed = ITSFilterKeys<AllKeys, 'debug', string | number>; // 'log' | 42 | 99\n * ```\n *\n * 三代版本對比:\n * ITSFilterKeysString: 固定處理 string(最基礎)\n * ITSFilterKeysPropertyKey: 固定處理 PropertyKey(更廣泛)\n * ITSFilterKeys: 可配置 AllowedPropertyKey 參數(最靈活)\n *\n * @see ITSExtractKeysV13\n */\nexport type ITSExcludeFilterKeys<T, ExcludeKeys extends PropertyKey = never, AllowedPropertyKey extends PropertyKey = PropertyKey> = T extends infer U\n\t? U extends AllowedPropertyKey\n\t\t? U extends ExcludeKeys ? never : U\n\t\t: never\n\t: never;\n\n/**\n * ITSExtractKeysV13 - 選擇器版本(只保留匹配 IncludeKeys 的鍵)\n *\n * 與 FilterKeysV3 的邏輯差異:\n * - FilterKeysV3: `U extends ExcludeKeys ? never : U` → 排除匹配的鍵\n * - ITSExtractKeysV13: `U extends IncludeKeys ? U : never` → 只保留匹配的鍵\n *\n * 設計理念:\n * ---------------------------\n * ExtractKeyofV12 系列的核心需求是「篩選符合 V 類型的鍵」。\n * FilterKeys 系列的設計是「排除」思維( ExcludeKeys ),\n * 而 ITSExtractKeysV13 採用「選擇」思維( IncludeKeys ),更符合鍵提取的語義。\n *\n * 與 FilterKeysV3 實作的對比:\n * - FilterKeysV3: `FilterKeysV3<T, never, V>`(用 AllowedPropertyKey 篩選,ExcludeKeys 設為 never)\n * - ITSExtractKeysV13: `ITSExtractKeysV13<T, V, PropertyKey>`(直接用 IncludeKeys 篩選)\n *\n * 使用範例與測試驗證:\n * ```typescript\n * type AllKeys = 'log' | 'debug' | 'error' | 42 | 99 | symbol;\n *\n * // 1. 篩選 string 類型鍵(等同 ExtractKeyofV12d<AllKeys, string>)\n * // ✅ 結果:'log' | 'debug' | 'error'\n * type Strings = ITSExtractKeysV13<AllKeys, string, PropertyKey>;\n *\n * // 2. 篩選 number 類型鍵\n * // ✅ 結果:42 | 99\n * type Numbers = ITSExtractKeysV13<AllKeys, number, PropertyKey>;\n *\n * // 3. 只保留特定字面量\n * // ✅ 結果:'log' | 'debug'\n * type Picked = ITSExtractKeysV13<AllKeys, 'log' | 'debug', PropertyKey>;\n *\n * // 4. 特定數字字面量(只保留 42,過濾 99)\n * // ✅ 結果:42\n * // ❌ 99 會被過濾\n * type SpecificNumber = ITSExtractKeysV13<AllKeys, 42, PropertyKey>;\n *\n * // 5. 實作 ExtractKeyofV12(輸出轉為 string)\n * // ✅ 結果:'log' | 'debug' | 'error'\n * type V12_Strings = ITSExtractKeysV13<AllKeys, string, PropertyKey> & string;\n *\n * // 6. 限制輸入類型為 string(等同 FilterKeysV3<AllKeys, never, string>)\n * // ✅ 結果:'log' | 'debug' | 'error'\n * // ❌ number/symbol 被過濾\n * type StringOnly = ITSExtractKeysV13<AllKeys, PropertyKey, string>;\n *\n * // 7. symbol 類型篩選(結果為 never)\n * // ✅ 結果:never(symbol 無法通過 PropertyKey 匹配 string/number)\n * type SymbolFiltered = ITSExtractKeysV13<AllKeys, symbol, PropertyKey>;\n * ```\n *\n * Enum 類型處理範例:\n * ------------------\n * TypeScript enum 作為類型時,需使用模板字面量 `${Enum}` 或 keyof typeof 獲取成員。\n *\n * ```typescript\n * enum LogLevel {\n * DEBUG = 'debug',\n * INFO = 'info',\n * WARN = 'warn',\n * ERROR = 'error'\n * }\n *\n * enum StatusCode {\n * OK = 200,\n * NOT_FOUND = 404,\n * ERROR = 500\n * }\n *\n * // 8. 從 enum 鍵中篩選(使用 keyof typeof)\n * // ✅ 結果:'DEBUG' | 'INFO'\n * type EnumKeys = keyof typeof LogLevel; // 'DEBUG' | 'INFO' | 'WARN' | 'ERROR'\n * type PickedEnumKeys = ITSExtractKeysV13<EnumKeys, 'DEBUG' | 'INFO', PropertyKey>;\n *\n * // 11. 數字 enum 的值篩選(使用 infer 提取數字)\n * // ✅ 結果:200 | 500\n * type StatusEnumValues = `${StatusCode}` extends `${infer N extends number}` ? N : never;\n * type PickedStatusValues = ITSExtractKeysV13<200 | 404 | 500, StatusEnumValues, PropertyKey>;\n *\n * // 12. enum 作為第二參數(IncludeKeys)使用 ITSTypeAndStringLiteral\n * // 搭配 ts-type 的 ITSTypeAndStringLiteral 可直接將 enum 轉為 string 字面量\n * // ✅ 結果:'debug' | 'error'\n * import { ITSTypeAndStringLiteral } from 'ts-type';\n * type MixedInput = ITSTypeAndStringLiteral<LogLevel> | 42 | symbol;\n * type EnumAsIncludeKeys = ITSTypeAndStringLiteral<LogLevel.DEBUG | LogLevel.ERROR>;\n * type Filtered = ITSExtractKeysV13<MixedInput, EnumAsIncludeKeys, PropertyKey>;\n * // ✅ 可賦值:LogLevel.DEBUG, LogLevel.ERROR\n * // ❌ 被過濾:'trace', 'fatal', 42, symbol\n *\n * // 13. 數字 enum 直接作為 IncludeKeys\n * // ✅ 結果:200 | 404 | 500\n * type AllCodes = 200 | 301 | 404 | 500 | 503;\n * type StatusCodes = ITSExtractKeysV13<AllCodes, StatusCode, PropertyKey>;\n * ```\n *\n * @see ITSExcludeFilterKeys\n */\nexport type ITSExtractKeysV13<T, IncludeKeys extends PropertyKey, AllowedPropertyKey extends PropertyKey = PropertyKey> = T extends infer U\n\t? U extends AllowedPropertyKey\n\t\t? U extends IncludeKeys ? U : never\n\t\t: never\n\t: never;\n\n"]}
|
package/lib/helper/infer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infer.js","sourceRoot":"","sources":["infer.ts"],"names":[],"mappings":";AAAA;;GAEG","sourcesContent":["/**\n * Created by user on 2019/6/12.\n */\n\n/**\n * 取得物件指定成員的值類型\n * Get the value type of a specific object member\n
|
|
1
|
+
{"version":3,"file":"infer.js","sourceRoot":"","sources":["infer.ts"],"names":[],"mappings":";AAAA;;GAEG","sourcesContent":["/**\n * Created by user on 2019/6/12.\n */\n\n/**\n * 取得物件指定成員的值類型\n * Get the value type of a specific object member\n *\n * @example\n * interface User {\n * name: string;\n * age: number;\n * }\n * type NameType = ITSValueOfMember<User, 'name'>; // string\n */\nexport type ITSValueOfMember<T, K extends keyof T> = T extends {\n\t[p in K]: infer U\n} ? U : never;\n\n/**\n * 取得具有 length 屬性之物件的 length 類型\n * Get the length type of an object with length property\n *\n * @example\n * type ArrayLike = { length: 42 };\n * type LengthType = ITSLengthOf<ArrayLike>; // 42\n */\nexport type ITSLengthOf<T extends {\n\tlength: number\n}> = ITSValueOfMember<T, 'length'>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intersection.js","sourceRoot":"","sources":["intersection.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * 將聯集類型轉換為交集類型\n * Convert union type to intersection type\n
|
|
1
|
+
{"version":3,"file":"intersection.js","sourceRoot":"","sources":["intersection.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * 將聯集類型轉換為交集類型\n * Convert union type to intersection type\n *\n * @see https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type\n * @example\n * type FunctionUnion = (() => void) | ((p: string) => void);\n * type FunctionIntersection = (() => void) & ((p: string) => void);\n * type SynthesizedFunctionIntersection = ITSUnionToIntersection<FunctionUnion>\n * // type SynthesizedFunctionIntersection = (() => void) & ((p: string) => void)\n */\nexport type ITSUnionToIntersection<U> =\n\t(U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never\n"]}
|
|
@@ -30,15 +30,52 @@ export type ITSValueOf<T extends Record<any, any>> = T[keyof T];
|
|
|
30
30
|
/** 取得介面所有值的聯集類型(別名)/ Get the union type of all values in an interface (alias) */
|
|
31
31
|
export type { ITSValueOf as ITSValueOfRecord };
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
33
|
+
* Extracts the keys of a type.
|
|
34
|
+
*
|
|
35
|
+
* For a union type, only keys shared by all union members are returned.
|
|
35
36
|
*
|
|
36
37
|
* @example
|
|
37
|
-
*
|
|
38
|
-
* type
|
|
39
|
-
*
|
|
38
|
+
* type A = { name: string; age: number };
|
|
39
|
+
* type B = { name: string; email: string };
|
|
40
|
+
*
|
|
41
|
+
* type Keys = ITSKeyOf<A | B>;
|
|
42
|
+
* // "name"
|
|
40
43
|
*/
|
|
41
44
|
export type ITSKeyOf<T> = keyof T;
|
|
45
|
+
/**
|
|
46
|
+
* Extracts all keys from every member of a union type.
|
|
47
|
+
*
|
|
48
|
+
* Unlike `keyof T`, this distributes over union members and returns
|
|
49
|
+
* the union of their keys.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* type A = { name: string; age: number };
|
|
53
|
+
* type B = { name: string; email: string };
|
|
54
|
+
*
|
|
55
|
+
* type Keys = ITSKeyOfUnion<A | B>;
|
|
56
|
+
* // "name" | "age" | "email"
|
|
57
|
+
*/
|
|
58
|
+
export type ITSKeyOfUnion<T> = T extends any ? keyof T : never;
|
|
59
|
+
/**
|
|
60
|
+
* Extracts the value type associated with a key from a union type.
|
|
61
|
+
*
|
|
62
|
+
* Only union members containing the specified key contribute their value type.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* type T =
|
|
66
|
+
* | { type: "a"; value: number }
|
|
67
|
+
* | { type: "b"; text: string };
|
|
68
|
+
*
|
|
69
|
+
* type Value = ITSValueOfUnion<T, "value">;
|
|
70
|
+
* // number
|
|
71
|
+
*
|
|
72
|
+
* type Text = ITSValueOfUnion<T, "text">;
|
|
73
|
+
* // string
|
|
74
|
+
*
|
|
75
|
+
* type Type = ITSValueOfUnion<T, "type">;
|
|
76
|
+
* // "a" | "b"
|
|
77
|
+
*/
|
|
78
|
+
export type ITSValueOfUnion<T, K extends ITSKeyOfUnion<T>> = T extends unknown ? K extends keyof T ? T[K] : never : never;
|
|
42
79
|
/**
|
|
43
80
|
* 取得指定鍵集合的值類型聯集
|
|
44
81
|
* Get the union of value types for a specified set of keys
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-value.js","sourceRoot":"","sources":["key-value.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 鍵值對類型操作工具\n * Key-Value Type Manipulation Utilities\n
|
|
1
|
+
{"version":3,"file":"key-value.js","sourceRoot":"","sources":["key-value.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 鍵值對類型操作工具\n * Key-Value Type Manipulation Utilities\n *\n * 提供類型安全的鍵值對操作工具,包括取得物件、Map、陣列的值類型等\n * Provides type-safe key-value pair manipulation utilities\n */\n\nimport { ITSMapLike } from '../generic';\nimport { ITSIteratorLazy } from './typeof';\nimport { ITSArrayListMaybeReadonly } from '../type/base';\n\n/**\n * 取得介面所有值的聯集類型\n * Get the union type of all values in an interface\n *\n * 類似 `Object.values()` 的類型版本,回傳物件所有值的聯集\n * Similar to the type version of `Object.values()`, returns the union of all object values\n *\n * @see https://stackoverflow.com/questions/49285864/is-there-a-valueof-similar-to-keyof-in-typescript\n *\n * @example\n * interface User {\n * name: string;\n * age: number;\n * isActive: boolean;\n * }\n * type UserValues = ITSValueOf<User>;\n * // type UserValues = string | number | boolean\n */\nexport type ITSValueOf<T extends Record<any, any>> = T[keyof T];\n\n/** 取得介面所有值的聯集類型(別名)/ Get the union type of all values in an interface (alias) */\nexport type { ITSValueOf as ITSValueOfRecord };\n\n/**\n * Extracts the keys of a type.\n *\n * For a union type, only keys shared by all union members are returned.\n *\n * @example\n * type A = { name: string; age: number };\n * type B = { name: string; email: string };\n *\n * type Keys = ITSKeyOf<A | B>;\n * // \"name\"\n */\nexport type ITSKeyOf<T> = keyof T;\n\n/**\n * Extracts all keys from every member of a union type.\n *\n * Unlike `keyof T`, this distributes over union members and returns\n * the union of their keys.\n *\n * @example\n * type A = { name: string; age: number };\n * type B = { name: string; email: string };\n *\n * type Keys = ITSKeyOfUnion<A | B>;\n * // \"name\" | \"age\" | \"email\"\n */\nexport type ITSKeyOfUnion<T> =\n\tT extends any ? keyof T : never;\n\n/**\n * Extracts the value type associated with a key from a union type.\n *\n * Only union members containing the specified key contribute their value type.\n *\n * @example\n * type T =\n * | { type: \"a\"; value: number }\n * | { type: \"b\"; text: string };\n *\n * type Value = ITSValueOfUnion<T, \"value\">;\n * // number\n *\n * type Text = ITSValueOfUnion<T, \"text\">;\n * // string\n *\n * type Type = ITSValueOfUnion<T, \"type\">;\n * // \"a\" | \"b\"\n */\nexport type ITSValueOfUnion<\n T,\n K extends ITSKeyOfUnion<T>\n> = T extends unknown\n ? K extends keyof T\n ? T[K]\n : never\n : never;\n\n/**\n * 取得指定鍵集合的值類型聯集\n * Get the union of value types for a specified set of keys\n *\n * @example\n * interface User { name: string; age: number; email: string; }\n * type PickedValues = ITSPickValueOf<User, 'name' | 'age'>;\n * // type PickedValues = string | number\n */\nexport type ITSPickValueOf<T, K extends keyof T> = ITSValueOf<Pick<T, K>>;\n\n/**\n * 迭代器值的類型\n * Iterator value type\n *\n * 從 Iterator 或 IteratorResult 類型中提取值類型\n * Extracts value type from Iterator or IteratorResult types\n *\n * @example\n * type IteratorResultType = ITSValueOfIterator<IteratorResult<string>>;\n * // type IteratorResultType = string[]\n */\nexport type ITSValueOfIterator<T extends ITSIteratorLazy<any>> =\n\t(T extends Iterator<infer U> ? U :\n\t\tT extends IteratorResult<infer U> ? U :\n\t\t\tany)[]\n\t;\n\n/**\n * Map 類型的所有值類型\n * All value types of Map type\n *\n * 提取 Map 類型的泛型參數 V,回傳 V[]\n * Extracts the generic parameter V from Map type, returns V[]\n *\n * @example\n * type MapValues = ITSValueOfMap<Map<string, number>>;\n * // type MapValues = number[]\n */\nexport type ITSValueOfMap<T extends ITSMapLike<any, any>> =\n\tT extends ITSMapLike<any, infer U> ? U[] :\n\t\tany[]\n\t;\n\n/**\n * 陣列的元素類型\n * Array element type\n *\n * 從陣列類型中提取元素類型,支援唯讀陣列和可讀寫陣列\n * Extracts element type from array type, supporting both readonly and writable arrays\n *\n * @example\n * type ArrayElement = ITSValueOfArray<string[]>;\n * // type ArrayElement = string\n *\n * @example\n * type ReadonlyArrayElement = ITSValueOfArray<readonly string[]>;\n * // type ReadonlyArrayElement = string\n */\nexport type ITSValueOfArray<T extends ITSArrayListMaybeReadonly<any>> =\n\tT extends readonly (infer U)[]\n\t\t? U : T extends (infer U)[]\n\t\t\t? U : never\n\t;\n\n/**\n * 類陣列的元素類型\n * Array-like element type\n *\n * 從類陣列物件(如 ArrayLike<T>)中提取元素類型\n * Extracts element type from array-like objects (such as ArrayLike<T>)\n *\n * @example\n * type ArrayLikeElement = ITSValueOfArrayLike<ArrayLike<string>>;\n * // type ArrayLikeElement = string\n */\nexport type ITSValueOfArrayLike<T extends ITSArrayListMaybeReadonly<any> | ArrayLike<any>> =\n\tT extends ITSArrayListMaybeReadonly<T>\n\t\t? ITSValueOfArray<T> : T extends ArrayLike<infer U>\n\t\t\t? U : never\n\t;\n"]}
|
package/lib/helper/number.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.js","sourceRoot":"","sources":["number.ts"],"names":[],"mappings":"","sourcesContent":["import { ITSToStringLiteral } from './string';\n\n/**\n * 將數字或 bigint 轉換為字串字面量類型\n * Convert number or bigint to string literal type\n
|
|
1
|
+
{"version":3,"file":"number.js","sourceRoot":"","sources":["number.ts"],"names":[],"mappings":"","sourcesContent":["import { ITSToStringLiteral } from './string';\n\n/**\n * 將數字或 bigint 轉換為字串字面量類型\n * Convert number or bigint to string literal type\n *\n * @example\n * type NumType = ITSNumberString<42>; // '42'\n */\nexport type ITSNumberString<N extends number | bigint = number> = ITSToStringLiteral<N>;\n\n/**\n * 從字串中解包出數字類型\n * Unpack number type from string\n *\n * @example\n * type Test = ITSNumberString<123>;\n * type Result = ITSUnpackNumberString<Test>; // 123\n */\nexport type ITSUnpackNumberString<S extends string, R = never> = S extends ITSNumberString<infer N> ? N : R;\n\n/**\n * 數字值類型:數字或字串\n * Number value type: number or string\n */\nexport type ITSNumberValue = number | string;\n\n/**\n * 數字值類型2:數字或數字字串\n * Number value type 2: number or number string\n */\nexport type ITSNumberValue2 = number | ITSNumberString;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readonly.js","sourceRoot":"","sources":["readonly.ts"],"names":[],"mappings":"","sourcesContent":["import { ITSValueOfArray } from './key-value';\n\n/**\n * 將類型的所有屬性設為唯讀且可選\n * Make all properties of a type readonly and optional\n
|
|
1
|
+
{"version":3,"file":"readonly.js","sourceRoot":"","sources":["readonly.ts"],"names":[],"mappings":"","sourcesContent":["import { ITSValueOfArray } from './key-value';\n\n/**\n * 將類型的所有屬性設為唯讀且可選\n * Make all properties of a type readonly and optional\n *\n * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html\n * @example\n * interface User {\n * name: string;\n * age: number;\n * }\n * type ReadonlyPartialUser = ITSReadonlyPartial<User>;\n * // { readonly name?: string; readonly age?: number; }\n */\nexport type ITSReadonlyPartial<T> = {\n\treadonly [P in keyof T]?: T[P]\n};\n\n/**\n * 將類型的所有屬性設為可讀寫\n * Make all properties of a type writable\n *\n * @example\n * interface User {\n * readonly name: string;\n * readonly age: number;\n * }\n * type WritableUser = ITSWriteable<User>;\n * // { name: string; age: number; }\n */\nexport type ITSWriteable<T> = ITSWriteablePick<T, keyof T>;\n\n/**\n * 將指定屬性設為可讀寫\n * Make specified properties writable\n *\n * @example\n * interface User {\n * readonly name: string;\n * readonly age: number;\n * readonly email: string;\n * }\n * type PartialWritable = ITSWriteablePick<User, 'name' | 'age'>;\n * // { name: string; age: number; readonly email?: string; }\n */\nexport type ITSWriteablePick<T, K extends keyof T = keyof T> = {\n\t-readonly [P in K]: T[P];\n};\n\n/**\n * 將指定屬性設為唯讀\n * Make specified properties readonly\n *\n * @example\n * interface User {\n * name: string;\n * age: number;\n * }\n * type ReadonlyPartial = ITSReadonlyPick<User, 'name'>;\n * // { readonly name: string; age?: number; }\n */\nexport type ITSReadonlyPick<T, K extends keyof T = keyof T> = {\n\treadonly [P in K]: T[P];\n};\n\n/**\n * 保留指定屬性可讀寫,其他屬性不變\n * Keep specified properties writable, other properties unchanged\n *\n * @example\n * interface User {\n * readonly name: string;\n * readonly age: number;\n * email: string;\n * }\n * type Result = ITSWriteableWith<User, 'email'>;\n * // { name: readonly string; age: readonly number; email: string; }\n */\nexport type ITSWriteableWith<T, K extends keyof T = keyof T> = Omit<T, K> & ITSWriteablePick<T, K>;\n\n/**\n * 保留指定屬性唯讀,其他屬性不變\n * Keep specified properties readonly, other properties unchanged\n *\n * @example\n * interface User {\n * name: string;\n * age: number;\n * email: string;\n * }\n * type Result = ITSReadonlyWith<User, 'name' | 'age'>;\n * // { readonly name: string; readonly age: number; email: string; }\n */\nexport type ITSReadonlyWith<T, K extends keyof T = keyof T> = Omit<T, K> & ITSReadonlyPick<T, K>;\n\n/**\n * 將唯讀陣列轉換為可讀寫陣列\n * Convert readonly array to writable array\n *\n * @example\n * type ReadonlyArray = readonly [1, 2, 3];\n * type WritableArray = ITSReadonlyToWriteableArray<ReadonlyArray>;\n * // [1, 2, 3]\n */\nexport type ITSReadonlyToWriteableArray<T extends readonly any[]> = Omit<T, keyof any[]> & ITSValueOfArray<T>[] & {\n\t-readonly [P in number | 'length']: T[P]\n};\n\n/**\n * 深層移除唯讀修飾符\n * Deeply remove readonly modifier\n *\n * @example\n * interface Nested {\n * readonly user: {\n * readonly name: string;\n * readonly profile: {\n * readonly age: number;\n * };\n * };\n * }\n * type WritableNested = ITSWriteableDeep<Nested>;\n * // { user: { name: string; profile: { age: number; } } }\n */\nexport type ITSWriteableDeep<T, K extends keyof T = keyof T> = T extends Record<any, any> ? {\n\t-readonly [P in K]: ITSWriteableDeep<T[P]>;\n} : T;\n\n/**\n * 深層添加唯讀修飾符\n * Deeply add readonly modifier\n *\n * @example\n * interface Nested {\n * user: {\n * name: string;\n * profile: {\n * age: number;\n * };\n * };\n * }\n * type ReadonlyNested = ITSReadonlyDeep<Nested>;\n * // { readonly user: { readonly name: string; readonly profile: { readonly age: number; } } }\n */\nexport type ITSReadonlyDeep<T, K extends keyof T = keyof T> =\n\tT extends Record<any, any> ? {\n\t\treadonly [P in K]: ITSReadonlyDeep<T[P]>;\n\t} : T;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.js","sourceRoot":"","sources":["enum.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 列舉類型工具\n * Enum Type Utilities\n
|
|
1
|
+
{"version":3,"file":"enum.js","sourceRoot":"","sources":["enum.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 列舉類型工具\n * Enum Type Utilities\n *\n * 提供列舉類型的操作工具\n * Provides enum type manipulation utilities\n */\n\nimport { ITSEnumLike, ITSNumberEnumLike } from '../../type/record/enum';\nimport { ITSValueOf } from '../key-value';\nimport { ITSStringInferToNumber } from '../string/infer';\nimport { ITSToStringLiteral } from '../string';\n\n/**\n * 從列舉類型中排除指定值\n * Exclude specified values from enum type\n *\n * @example\n * enum Color { Red, Green, Blue }\n * type ExcludedRed = ITSExcludeEnumValue<Color, Color.Red>;\n * // type ExcludedRed = Color.Green | Color.Blue\n */\nexport type ITSExcludeEnumValue<Enum extends ITSEnumLike, U extends ITSValueOf<Enum>> = Exclude<ITSValueOf<Enum>, U>;\n\n/**\n * 從列舉類型中提取指定值\n * Extract specified values from enum type\n *\n * @example\n * enum Color { Red, Green, Blue }\n * type ExtractedRed = ITSExtractEnumValue<Color, Color.Red>;\n * // type ExtractedRed = Color.Red\n */\nexport type ITSExtractEnumValue<Enum extends ITSEnumLike, U extends ITSValueOf<Enum>> = Extract<ITSValueOf<Enum>, U>;\n\n/**\n * 將數字列舉轉換為純數字類型\n * Convert number enum to pure number type\n *\n * @example\n * enum Status { Active = 1, Inactive = 2 }\n * type NumStatus = ITSNumberEnumToNumber<Status>;\n * // type NumStatus = 1 | 2\n */\nexport type ITSNumberEnumToNumber<T extends number> = ITSStringInferToNumber<ITSToStringLiteral<Extract<T, number>>>\n\n/**\n * 數字列舉與數字的聯合類型\n * Union type of number enum and number\n *\n * @example\n * enum Status { Active = 1, Inactive = 2 }\n * type StatusValue = ITSNumberEnumAndNumber<Status>;\n * // type StatusValue = 1 | 2 | number\n */\nexport type ITSNumberEnumAndNumber<T extends number> = Extract<T, number> | ITSNumberEnumToNumber<T>\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"member.js","sourceRoot":"","sources":["member.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 記錄成員工具\n * Record Member Utilities\n
|
|
1
|
+
{"version":3,"file":"member.js","sourceRoot":"","sources":["member.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 記錄成員工具\n * Record Member Utilities\n *\n * 提供提取物件成員(方法)的工具類型\n * Provides utility types for extracting object members (methods)\n */\n\nimport { ITSExtractRecord, ITSPickByType } from './pick-type';\nimport { ITSPropertyKey } from '../../type/base';\nimport { ITSExtractKeyof } from '../filter';\n\n/**\n * 過濾出所有成員是函數且鍵類型為字串或符號的屬性\n * Filter out all members that are functions and key types are string or symbol\n *\n * @example\n * class User {\n * name: string;\n * greet(): void;\n * async fetch(): Promise<void>;\n * }\n * type Methods = ITSMemberMethods<User>;\n * // type Methods = { greet(): void; fetch(): Promise<void>; }\n */\nexport type ITSMemberMethods<T> = ITSPickByType<T, Function, Extract<keyof T, ITSPropertyKey>>;\n\n/**\n * 取得物件方法的鍵\n * Get keys of object methods\n *\n * @example\n * class User {\n * name: string;\n * greet(): void;\n * async fetch(): Promise<void>;\n * }\n * type MethodKeys = ITSKeyofMemberMethods<User>;\n * // type MethodKeys = \"greet\" | \"fetch\"\n */\nexport type ITSKeyofMemberMethods<T> = ITSExtractKeyof<ITSMemberMethods<T>, ITSPropertyKey>;\n\n/**\n * 版本 12: 完全泛化版 - 支持任意鍵值類型與自定義條件\n * 可配置:1) 值類型條件 2) 鍵排除列表 3) 輸出鍵類型\n *\n * ✅ 跨模組驗證:使用 infer 延遲類型解析,即使跨模組引用也能正確運作,\n * 避免 IMethods 變為 string 的問題\n *\n * @example\n * ```\n * type IMethods2 = \"assert\" | \"clear\" | \"count\" | \"countReset\" | \"debug\"\n * | \"dir\" | \"dirxml\" | \"error\" | \"group\" | \"groupCollapsed\" | \"groupEnd\"\n * | \"info\" | \"log\" | \"table\" | \"time\" | \"timeEnd\" | \"timeLog\" | \"timeStamp\"\n * | \"trace\" | \"warn\" | \"profile\" | \"profileEnd\"\n * export type IMethods2 = ITSExcludeFilterKeys<ITSExtractKeysV13<ITSMemberMethodsV12<Console, Function, 'constructor'>, string>, \"Console\" | 'new' | 'prototype' | 'Console' | 'length'>;\n * ```\n *\n * 類型參數:\n * - T: 輸入對象類型(需 extends object)\n * - ValueCond: 值類型條件(預設為函數類型 `(...args: any[]) => any`)\n * - ExcludeKeys: 要排除的鍵列表(預設為 never,不排除任何鍵)\n *\n * 與 MemberMethodsV11 的差異:\n * - V11: 固定排除函數類型的鍵,只能排除單個鍵\n * - V12: 可自定義值類型條件(如只提取返回 Promise 的方法),支持排除多個鍵\n *\n * 核心機制:\n * ---------------------------\n * 1. 使用 `T extends infer U` 捕獲輸入類型,實現跨模組延遲解析\n * 2. 映射類型遍歷所有鍵,篩選符合 ValueCond 的鍵\n * 3. 若 ExcludeKeys 不為 never,使用 `as` 重映射排除指定鍵\n *\n * ✅ 跨模組驗證:使用 infer 延遲類型解析,即使跨模組引用也能正確運作,\n * 避免 IMethods 變為 string 的問題\n *\n * 使用範例:\n * ---------------------------\n * @example\n * ```typescript\n * interface MyClass {\n * name: string;\n * log(): void;\n * debug(): void;\n * error(): void;\n * constructor(): void;\n * _privateMethod(): void;\n * }\n *\n * // 1. 提取所有方法(預設行為,等同 MemberMethodsV11 無排除時)\n * // ✅ 結果:'log' | 'debug' | 'error' | 'constructor' | '_privateMethod'\n * type AllMethods = MemberMethodsV12<MyClass>;\n *\n * // 2. 提取方法但排除 constructor\n * // ✅ 結果:'log' | 'debug' | 'error' | '_privateMethod'\n * // ❌ 'constructor' 被排除\n * type NoCtor = MemberMethodsV12<MyClass, (...args: any[]) => any, 'constructor'>;\n *\n * // 3. 排除多個鍵\n * // ✅ 結果:'log' | 'debug' | 'error'\n * // ❌ 'constructor'、'_privateMethod' 被排除\n * type PublicMethods = MemberMethodsV12<MyClass, (...args: any[]) => any, 'constructor' | '_privateMethod'>;\n *\n * // 4. 自定義值類型條件 - 只提取返回 string 的方法\n * interface StringReturnClass {\n * getName(): string;\n * getId(): number;\n * log(): void;\n * }\n * // ✅ 結果:'getName'\n * type StringMethods = MemberMethodsV12<StringReturnClass, () => string>;\n *\n * // 5. 自定義值類型 - 只提取返回 Promise 的方法\n * interface AsyncClass {\n * fetchData(): Promise<string>;\n * syncMethod(): string;\n * save(): Promise<void>;\n * }\n * // ✅ 結果:'fetchData' | 'save'\n * type AsyncMethods = MemberMethodsV12<AsyncClass, () => Promise<any>>;\n *\n * // 6. 泛型類別中使用\n * class GenericService<T> {\n * data: T;\n * fetch(): Promise<T>;\n * save(): Promise<void>;\n * private internal(): void;\n * }\n * // ✅ 結果:'fetch' | 'save' | 'internal'(含私有方法)\n * // ❌ 'data' 被過濾(不是函數)\n * type ServiceMethods = MemberMethodsV12<GenericService<any>>;\n * // ✅ 結果:'fetch' | 'save'\n * // ❌ 'internal' 也被排除(假設要排除私有方法)\n * type PublicServiceMethods = MemberMethodsV12<GenericService<any>, (...args: any[]) => any, 'internal'>;\n *\n * // 7. 與 ExtractKeyofV12 組合使用 - 提取並轉換為 string 類型\n * type MyClassMethods = MemberMethodsV12<MyClass>;\n * type StringMethodKeys = ExtractKeyofV12<MyClassMethods, string>; // 'log' | 'debug' | 'error' | ...\n *\n * // 8. 內化排除模式 - 最簡潔用法\n * // 將所有排除邏輯集中在 MemberMethodsV12 的 ExcludeKeys 參數中\n * type CleanMethods = MemberMethodsV12<\n * MyClass,\n * Function,\n * 'constructor' | 'new' | 'prototype' | '_privateMethod'\n * >;\n * ```\n *\n * 進階組合範例:\n * ---------------------------\n * @example\n * ```typescript\n * // 組合 FilterKeys 實現分階段過濾\n * type Stage1 = MemberMethodsV12<ApiA>; // 提取 A 的方法\n * type Stage2 = MemberMethodsV12<ApiB>; // 提取 B 的方法\n * type Combined = FilterKeys<Stage1 | Stage2, 'constructor' | 'init'>;\n *\n * // 條件化排除\n * type ConditionalMethods<T, ExcludePrivate extends boolean> =\n * ExcludePrivate extends true\n * ? MemberMethodsV12<T, (...args: any[]) => any, `_${string}`>\n * : MemberMethodsV12<T>;\n * ```\n *\n * @see ITSExcludeFilterKeys\n * @see ITSExtractKeysV13\n */\nexport type ITSMemberMethodsV12<\n\tT,\n\tValueCond = (...args: any[]) => any,\n\tExcludeKeys extends PropertyKey = never\n>\t// 1. T extends infer U - 使用 infer 捕獲輸入類型,實現延遲解析\n\t= T extends infer U\n\t// 2. U extends object - 確保輸入是對象類型(可遍歷鍵)\n\t? U extends object\n\t\t// 3. ExcludeKeys extends never - 檢查是否需要排除特定鍵\n\t\t? ExcludeKeys extends never\n\t\t\t// 3a. 無需排除 - 使用基本映射類型遍歷所有鍵\n\t\t\t// 遍歷 U 的所有鍵 K,若值類型 U[K] 符合 ValueCond 則保留 K,否則設為 never\n\t\t\t? { [K in keyof U]: U[K] extends ValueCond ? K : never; }[keyof U]\n\t\t\t// 3b. 需要排除 - 使用「as」重映射語法進行鍵過濾\n\t\t\t// 邏輯:先檢查值類型是否符合 ValueCond,再檢查鍵是否在 ExcludeKeys 中\n\t\t\t: {\n\t\t\t\t[K in keyof U as U[K] extends ValueCond\n\t\t\t\t\t// 若值符合條件,進一步檢查鍵是否需要排除\n\t\t\t\t\t? K extends ExcludeKeys ? never : K // 在排除列表中則設為 never,否則保留 K\n\t\t\t\t\t// 若值不符合條件,設為 never(過濾掉)\n\t\t\t\t\t: never]: any\n\t\t\t} extends infer M ? keyof M : never\n\t\t// U 不是 object,返回 never(無法提取方法)\n\t\t: never\n\t// T 無法解析為 infer U,返回 never\n\t: never;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"omit-index.js","sourceRoot":"","sources":["omit-index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 索引簽名移除工具\n * Index Signature Removal Utilities\n
|
|
1
|
+
{"version":3,"file":"omit-index.js","sourceRoot":"","sources":["omit-index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 索引簽名移除工具\n * Index Signature Removal Utilities\n *\n * 提供移除物件索引簽名的工具類型\n * Provides utility types for removing object index signatures\n */\n\n/**\n * 移除索引簽名\n * Remove index signature\n *\n * 從物件類型中移除索引簽名,保留明確宣告的鍵\n * Removes index signature from object type, keeping explicitly declared keys\n *\n * @see https://stackoverflow.com/a/51956054/4563339\n *\n * @example\n * interface WithIndex {\n * name: string;\n * [key: string]: any;\n * }\n * type WithoutIndex = ITSOmitIndexSignatures<WithIndex>;\n * // type WithoutIndex = { name: string }\n */\nexport type ITSOmitIndexSignatures<T extends Record<any, any>> = {\n\t[K in keyof T as string extends K ? never : number extends K ? never : K]: T[K]\n};\n\n/**\n * 取得已知的鍵(排除索引簽名)\n * Get known keys (excluding index signature)\n *\n * @example\n * interface WithIndex {\n * name: string;\n * [key: string]: any;\n * }\n * type Keys = ITSKnownKeys<WithIndex>;\n * // type Keys = \"name\"\n */\nexport type ITSKnownKeys<T extends Record<any, any>> = keyof ITSOmitIndexSignatures<T>;\n\n/**\n * 取得已知的鍵(另一種實現)\n * Get known keys (alternative implementation)\n *\n * @example\n * interface WithIndex {\n * name: string;\n * age: number;\n * [key: string]: any;\n * }\n * type Keys = ITSKnownKeys2<WithIndex>;\n * // type Keys = \"name\" | \"age\"\n */\nexport type ITSKnownKeys2<T> = {\n\t[K in keyof T]: string extends K ? never : number extends K ? never : K\n} extends { [_ in keyof T]: infer U } ? U : never;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"partial.js","sourceRoot":"","sources":["partial.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 記錄部分鍵檢測工具\n * Record Partial Key Detection Utilities\n
|
|
1
|
+
{"version":3,"file":"partial.js","sourceRoot":"","sources":["partial.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 記錄部分鍵檢測工具\n * Record Partial Key Detection Utilities\n *\n * 提供檢測物件鍵是否為可選的工具類型\n * Provides utility types for detecting if object keys are optional\n */\n\n/**\n * 檢測鍵是否為物件的部分鍵(可選鍵)\n * Check if key is a partial key (optional key) of the record\n *\n * 如果排除指定鍵後的類型可以賦值給原始類型,則該鍵為可選鍵\n * If the type after excluding the specified key is assignable to the original type, the key is optional\n *\n * @example\n * interface User {\n * name: string;\n * age?: number;\n * }\n * type PartialKeys = ITSKeyIsPartialOfRecord<User, 'age'>;\n * // type PartialKeys = \"age\"\n *\n * @example\n * interface User {\n * name: string;\n * age: number;\n * }\n * type PartialKeys = ITSKeyIsPartialOfRecord<User, 'age'>;\n * // type PartialKeys = never\n */\nexport type ITSKeyIsPartialOfRecord<T, K extends keyof T> = Omit<T, K> extends T ? K : never;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pick-type.js","sourceRoot":"","sources":["pick-type.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * @see https://github.com/type-challenges/type-challenges/blob/master/questions/2595-medium-pickbytype/README.md\n * @see https://github.com/type-challenges/type-challenges/issues/3814\n */\nimport { ITSNullPrimitive } from '../../type/base';\nimport { ITSValueOf } from '../key-value';\nimport { ITSExclude2, ITSExtract2 } from '../filter';\n\nexport type ITSKeyofByExtractType<T extends Record<keyof any, any>, U, K extends keyof T = keyof T> = K extends keyof T
|
|
1
|
+
{"version":3,"file":"pick-type.js","sourceRoot":"","sources":["pick-type.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * @see https://github.com/type-challenges/type-challenges/blob/master/questions/2595-medium-pickbytype/README.md\n * @see https://github.com/type-challenges/type-challenges/issues/3814\n */\nimport { ITSNullPrimitive } from '../../type/base';\nimport { ITSValueOf } from '../key-value';\nimport { ITSExclude2, ITSExtract2 } from '../filter';\n\nexport type ITSKeyofByExtractType<T extends Record<keyof any, any>, U, K extends keyof T = keyof T> = K extends keyof T\n\t? T[K] extends U ? K : never\n\t: never;\n\n/**\n * @see https://github.com/type-challenges/type-challenges/blob/master/questions/2595-medium-pickbytype/README.md\n * @see https://github.com/type-challenges/type-challenges/issues/3814\n */\nexport type ITSKeyofByExcludeType<T extends Record<keyof any, any>, U, K extends keyof T = keyof T> = K extends keyof T\n\t? T[K] extends U ? never : K\n\t: never;\n\n/**\n * From `T`, pick a set of properties whose type are assignable to `U`.\n *\n * @example\ntype OmitBoolean = ITSPickByType<{\n name: string\n count: number\n isReadonly: boolean\n isEnable: boolean\n}, boolean>\n *\n * @see https://github.com/type-challenges/type-challenges/blob/master/questions/2595-medium-pickbytype/README.md\n * @see https://github.com/type-challenges/type-challenges/issues/3814\n */\nexport type ITSPickByType<T extends Record<keyof any, any>, U, K extends keyof T = keyof T> = {\n\t[P in ITSKeyofByExtractType<T, U, K>]: T[P]\n}\n\n/**\n * From `T`, pick a set of properties whose type are not assignable to `U`.\n *\n * @example\ntype OmitBoolean = ITSOmitByType<{\n name: string\n count: number\n isReadonly: boolean\n isEnable: boolean\n}, boolean>\n *\n * @see https://github.com/type-challenges/type-challenges/blob/master/questions/2595-medium-pickbytype/README.md\n * @see https://github.com/type-challenges/type-challenges/issues/3814\n */\nexport type ITSOmitByType<T extends Record<keyof any, any>, U, K extends keyof T = keyof T> = {\n\t[P in ITSKeyofByExcludeType<T, U, K>]: T[P]\n}\n\n/**\n * @internal\n */\nexport type ITSRecordExcludeToKey<Base, Type> = {\n\t[Key in keyof Base]: ITSExclude2<Base[Key], Type, Key>\n};\n/**\n * @internal\n */\nexport type ITSRecordExtractToKey<Base, Type> = {\n\t[Key in keyof Base]: ITSExtract2<Base[Key], Type, Key>\n};\n\nexport type ITSKeyOfRecordExcludeToKey<Base, Type> = ITSValueOf<ITSRecordExcludeToKey<Base, Type>>;\nexport type ITSKeyOfRecordExtractToKey<Base, Type> = ITSValueOf<ITSRecordExtractToKey<Base, Type>>;\n\nexport type ITSPickRecordType<Base, Type> = Pick<Base, ITSKeyOfRecordExtractToKey<Base, Type>>;\nexport type ITSOmitRecordType<Base, Type> = Pick<Base, ITSKeyOfRecordExcludeToKey<Base, Type>>;\n\n/**\n * @deprecated use `ITSPickByType<M, T, K>`\n */\nexport type ITSExtractRecord<M, T, K extends keyof M = keyof M> = ITSPickByType<M, T, K>\n\nexport type ITSExtractRecordNoNull<M, T, K extends keyof M = keyof M> = {\n\t[P in K]: NonNullable<M[P]>;\n};\n\n/**\n * @deprecated use `ITSOmitByType<M, T, K>`\n */\nexport type ITSExcludeRecord<M, T, K extends keyof M = keyof M> = ITSOmitByType<M, T, K>;\n\nexport type ITSExcludeRecordNoNull<M, T, K extends keyof M = keyof M> = ITSOmitByType<M, ITSNullPrimitive, K>;\n\n/**\n * @deprecated use `ITSKeyofByExtractType<T, U, K>`\n */\nexport type ITSExtractKeyofRecord<M, T, K extends keyof M = keyof M> = ITSKeyofByExtractType<M, T, K>;\n\n/**\n * @deprecated use `ITSKeyofByExcludeType<M, T, K>`\n */\nexport type ITSExcludeKeyofRecord<M, T, K extends keyof M = keyof M> = ITSKeyofByExcludeType<M, T, K>;\n"]}
|
package/lib/helper/record.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.js","sourceRoot":"","sources":["record.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * 記錄(Record)類型操作工具\n * Record Type Manipulation Utilities\n
|
|
1
|
+
{"version":3,"file":"record.js","sourceRoot":"","sources":["record.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * 記錄(Record)類型操作工具\n * Record Type Manipulation Utilities\n *\n * 提供物件鍵盤操作的工具類型\n * Provides utility types for object key manipulation\n *\n * @see https://stackoverflow.com/a/55479659/4563339\n */\n\nexport type { ITSKeyIsPartialOfRecord } from './record/partial';\n\n/**\n * 取得物件的唯讀鍵集合\n * Get the readonly keys of an object\n *\n * 回傳一個由物件所有唯讀鍵組成的聯集類型\n * Returns a union type consisting of all readonly keys of the object\n *\n * @see https://github.com/type-challenges/type-challenges/blob/master/questions/5-extreme-readonly-keys/README.md\n * @see https://github.com/type-challenges/type-challenges/issues/87\n *\n * @alias ITSGetReadonlyKeys\n *\n * @example\n * interface Todo {\n * readonly title: string\n * readonly description: string\n * completed: boolean\n * }\n * type Keys = ITSKeyOfRecordExtractReadonly<Todo>\n * // expected to be \"title\" | \"description\"\n */\nexport type ITSKeyOfRecordExtractReadonly<T> = {\n\t[K in keyof T]-?: (<U>() => U extends { -readonly [P in K]: T[K] }\n\t\t? 1\n\t\t: 2) extends (<U>() => U extends { [P in K]: T[K] } ? 1 : 2) ? never : K\n}[keyof T];\n\n/** 取得物件的唯讀鍵集合(別名)/ Get the readonly keys of an object (alias) */\nexport type { ITSKeyOfRecordExtractReadonly as ITSGetReadonlyKeys }\n\n/**\n * 取得物件的非唯讀鍵集合\n * Get the non-readonly keys of an object\n *\n * 回傳一個由物件所有可寫入鍵組成的聯集類型\n * Returns a union type consisting of all writable keys of the object\n *\n * @example\n * interface Todo {\n * readonly title: string\n * readonly description: string\n * completed: boolean\n * }\n * type Keys = ITSKeyOfRecordExcludeReadonly<Todo>\n * // expected to be \"completed\"\n */\nexport type ITSKeyOfRecordExcludeReadonly<T> = Exclude<keyof T, ITSKeyOfRecordExtractReadonly<T>>\n\n/**\n * 檢查指定鍵是否為物件的唯讀鍵\n * Check if the specified key is a readonly key of the object\n *\n * @example\n * interface Todo {\n * readonly title: string\n * completed: boolean\n * }\n * type IsReadonly = ITSKeyIsReadonlyOfRecord<Todo, 'title'>;\n * // type IsReadonly = \"title\"\n */\nexport type ITSKeyIsReadonlyOfRecord<T, K extends ITSKeyOfRecordExtractReadonly<T>> = Extract<K, ITSKeyOfRecordExtractReadonly<T>>;\n\n/**\n * 檢查指定鍵是否為物件的非唯讀鍵\n * Check if the specified key is a non-readonly key of the object\n *\n * @example\n * interface Todo {\n * readonly title: string\n * completed: boolean\n * }\n * type IsWritable = ITSKeyIsNotReadonlyOfRecord<Todo, 'completed'>;\n * // type IsWritable = \"completed\"\n */\nexport type ITSKeyIsNotReadonlyOfRecord<T, K extends ITSKeyOfRecordExcludeReadonly<T>> = Extract<K, ITSKeyOfRecordExcludeReadonly<T>>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infer.js","sourceRoot":"","sources":["infer.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 字串類型推斷工具\n * String Type Inference Utilities\n
|
|
1
|
+
{"version":3,"file":"infer.js","sourceRoot":"","sources":["infer.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 字串類型推斷工具\n * String Type Inference Utilities\n *\n * 提供從字串字面量類型推斷基礎類型的工具\n * Provides utilities for inferring base types from string literal types\n */\n\nimport { ITSToStringLiteralAllowedType } from '../string';\n\n/**\n * 從字串推斷指定類型\n * Infer specified type from string\n *\n * 嘗試將字串字面量類型推斷為指定的基礎類型\n * Attempts to infer a specified base type from a string literal type\n *\n * @example\n * type Num = ITSStringInferToType<'123', number>;\n * // type Num = 123\n *\n * @example\n * type Bool = ITSStringInferToType<'true', boolean>;\n * // type Bool = true\n */\nexport type ITSStringInferToType<Str extends string, Type extends ITSToStringLiteralAllowedType, R = never> =\n\tStr extends `${infer U extends Type}`\n\t\t? U\n\t\t: R;\n\n/**\n * 從字串推斷數字類型\n * Infer number type from string\n *\n * @example\n * type Num = ITSStringInferToNumber<'123'>;\n * // type Num = 123\n */\nexport type ITSStringInferToNumber<Str extends string, R = never> = ITSStringInferToType<Str, number, R>\n\n/**\n * 從字串推斷布林類型\n * Infer boolean type from string\n *\n * @example\n * type Bool = ITSStringInferToBoolean<'true'>;\n * // type Bool = true\n */\nexport type ITSStringInferToBoolean<Str extends string, R = never> = ITSStringInferToType<Str, boolean, R>\n\n/**\n * 從字串推斷 null 類型\n * Infer null type from string\n *\n * @example\n * type Null = ITSStringInferToNull<'null'>;\n * // type Null = null\n */\nexport type ITSStringInferToNull<Str extends string, R = never> = ITSStringInferToType<Str, null, R>\n\n/**\n * 從字串推斷 undefined 類型\n * Infer undefined type from string\n *\n * @example\n * type Undefined = ITSStringInferToUndefined<'undefined'>;\n * // type Undefined = undefined\n */\nexport type ITSStringInferToUndefined<Str extends string, R = never> = ITSStringInferToType<Str, undefined, R>\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"literal-string.js","sourceRoot":"","sources":["literal-string.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 字串大小寫轉換工具\n * String Case Conversion Utilities\n
|
|
1
|
+
{"version":3,"file":"literal-string.js","sourceRoot":"","sources":["literal-string.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 字串大小寫轉換工具\n * String Case Conversion Utilities\n *\n * 提供字串命名字面量的大小寫轉換工具\n * Provides string naming literal case conversion utilities\n */\n\n/**\n * 將連字符命名字符串轉換為 PascalCase\n * Convert kebab-case string literal to PascalCase\n *\n * @see yargs\n *\n * @example\n * type Result = ITSPascalCase<'foo-bar'>;\n * // type Result = \"FooBar\"\n *\n * @example\n * type Result = ITSPascalCase<'foo-bar-baz'>;\n * // type Result = \"FooBarBaz\"\n */\nexport type ITSPascalCase<S extends string> = string extends S\n\t? string\n\t: S extends `${infer T}-${infer U}`\n\t\t? `${Capitalize<T>}${ITSPascalCase<U>}`\n\t\t: Capitalize<S>;\n\n/**\n * 將連字符命名字符串轉換為 camelCase\n * Convert kebab-case string literal to camelCase\n *\n * @see yargs\n *\n * @example\n * type Result = ITSCamelCase<'foo-bar'>;\n * // type Result = \"fooBar\"\n *\n * @example\n * type Result = ITSCamelCase<'foo-bar-baz'>;\n * // type Result = \"fooBarBaz\"\n */\nexport type ITSCamelCase<S extends string> = string extends S\n\t? string\n\t: S extends `${infer T}-${infer U}`\n\t\t? `${T}${ITSPascalCase<U>}`\n\t\t: S;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations.js","sourceRoot":"","sources":["operations.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 字串操作工具\n * String Operation Utilities\n
|
|
1
|
+
{"version":3,"file":"operations.js","sourceRoot":"","sources":["operations.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 字串操作工具\n * String Operation Utilities\n *\n * 提供字串相關的類型操作工具\n * Provides string-related type manipulation utilities\n */\n\n/**\n * 字串首字母大寫\n * Capitalize first letter of string\n *\n * @example\n * type Result = ITSCapitalize<'hello'>; // 'Hello'\n * type Result2 = ITSCapitalize<'world'>; // 'World'\n */\nexport type ITSCapitalize<S extends string> = S extends `${infer First}${infer Rest}`\n\t? `${Uppercase<First>}${Rest}`\n\t: S;\n\n/**\n * 字串首字母小寫\n * Uncapitalize first letter of string\n *\n * @example\n * type Result = ITSUncapitalize<'Hello'>; // 'hello'\n * type Result2 = ITSUncapitalize<'World'>; // 'world'\n */\nexport type ITSUncapitalize<S extends string> = S extends `${infer First}${infer Rest}`\n\t? `${Lowercase<First>}${Rest}`\n\t: S;\n\n/**\n * 字串轉為大寫\n * Convert string to uppercase\n *\n * @example\n * type Result = ITSToUpperCase<'hello'>; // 'HELLO'\n * type Result2 = ITSToUpperCase<'World'>; // 'WORLD'\n */\nexport type ITSToUpperCase<S extends string> = Uppercase<S>;\n\n/**\n * 字串轉為小寫\n * Convert string to lowercase\n *\n * @example\n * type Result = ITSToLowerCase<'HELLO'>; // 'hello'\n * type Result2 = ITSToLowerCase<'World'>; // 'world'\n */\nexport type ITSToLowerCase<S extends string> = Lowercase<S>;\n\n/**\n * TODO: 字串重複指定次數 - 無法實現\n * Repeat string specified number of times\n *\n * TypeScript 無法在類型層級進行遞迴數學運算\n * TypeScript cannot perform recursive mathematical operations at type level\n *\n * @example\n * type Result = ITSRepeat<'abc', 3>; // 'abcabcabc'\n * type Result2 = ITSRepeat<'x', 5>; // 'xxxxx'\n */\n// export type ITSRepeat<S extends string, N extends number> = never;\n\n// 保留原始實現作為參考 / Keep original implementation for reference\n// export type ITSRepeat<S extends string, N extends number> = \n// \tN extends 0 \n// \t\t? '' \n// \t\t: N extends infer Count \n// \t\t\t? Count extends number \n// \t\t\t\t? `${S}${ITSRepeat<S, Count extends 0 ? never : Count - 1>}`\n// \t\t\t\t: never \n// \t\t\t: never;\n\n/**\n * TODO: 字串長度 - 無法實現\n * Get string length\n *\n * TypeScript 無法在類型層級計算字串長度\n * TypeScript cannot calculate string length at type level\n *\n * @example\n * type Result = ITSStringLength<'hello'>; // 5\n * type Result2 = ITSStringLength<''>; // 0\n */\n// export type ITSStringLength<S extends string> = never;\n\n// 保留原始實現作為參考 / Keep original implementation for reference\n// export type ITSStringLength<S extends string, Counter extends any[] = []> = \n// \tS extends `${string}${infer Rest}` \n// \t\t? ITSStringLength<Rest, [...Counter, any]>\n// \t\t: Counter['length'];\n\n/**\n * TODO: 字串分割 - 無法實現\n * Split string by separator\n *\n * TypeScript 無法在類型層級進行字串分割操作\n * TypeScript cannot perform string splitting operations at type level\n *\n * @example\n * type Result = ITSSplit<'a,b,c', ','>; // ['a', 'b', 'c']\n * type Result2 = ITSSplit<'hello world', ' '>; // ['hello', 'world']\n */\n// export type ITSSplit<S extends string, Separator extends string> = never;\n\n// 保留原始實現作為參考 / Keep original implementation for reference\n// export type ITSSplit<S extends string, Separator extends string> = \n// \tS extends `${infer First}${Separator}${infer Rest}`\n// \t\t? [First, ...ITSSplit<Rest, Separator>]\n// \t\t: [S];\n\n/**\n * TODO: 字串連接 - 無法實現\n * Join string array with separator\n *\n * TypeScript 無法在類型層級進行陣列連接操作\n * TypeScript cannot perform array joining operations at type level\n *\n * @example\n * type Result = ITSJoin<['a', 'b', 'c'], ','>; // 'a,b,c'\n * type Result2 = ITSJoin<['hello', 'world'], ' '>; // 'hello world'\n */\n// export type ITSJoin<T extends string[], Separator extends string> = never;\n\n// 保留原始實現作為參考 / Keep original implementation for reference\n// export type ITSJoin<T extends string[], Separator extends string> = \n// \tT extends [infer First, ...infer Rest]\n// \t\t? First extends string\n// \t\t\t? Rest extends string[]\n// \t\t\t\t? Rest['length'] extends 0\n// \t\t\t\t\t? First\n// \t\t\t\t\t: `${First}${Separator}${ITSJoin<Rest, Separator>}`\n// \t\t\t\t: never\n// \t\t\t: never\n// \t\t: '';\n\n/**\n * 字串替換\n * Replace substring in string\n *\n * @example\n * type Result = ITSReplace<'hello world', 'world', 'typescript'>; // 'hello typescript'\n * type Result2 = ITSReplace<'abc123', '123', '456'>; // 'abc456'\n */\nexport type ITSReplace<S extends string, Search extends string, Replace extends string> =\n\tS extends `${infer Prefix}${Search}${infer Suffix}`\n\t\t? `${Prefix}${Replace}${Suffix}`\n\t\t: S;\n\n/**\n * 字串是否包含子字串\n * Check if string contains substring\n *\n * @example\n * type Result = ITSIncludes<'hello world', 'world'>; // true\n * type Result2 = ITSIncludes<'hello world', 'typescript'>; // false\n */\nexport type ITSIncludes<S extends string, Search extends string> =\n\tS extends `${string}${Search}${string}` ? true : false;\n\n/**\n * 字串是否以指定前綴開始\n * Check if string starts with prefix\n *\n * @example\n * type Result = ITSStartsWith<'hello world', 'hello'>; // true\n * type Result2 = ITSStartsWith<'hello world', 'world'>; // false\n */\nexport type ITSStartsWith<S extends string, Prefix extends string> =\n\tS extends `${Prefix}${string}` ? true : false;\n\n/**\n * 字串是否以指定後綴結束\n * Check if string ends with suffix\n *\n * @example\n * type Result = ITSEndsWith<'hello world', 'world'>; // true\n * type Result2 = ITSEndsWith<'hello world', 'hello'>; // false\n */\nexport type ITSEndsWith<S extends string, Suffix extends string> =\n\tS extends `${string}${Suffix}` ? true : false;\n"]}
|
package/lib/helper/string.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.js","sourceRoot":"","sources":["string.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 字面量類型工具\n * Literal Type Utilities\n
|
|
1
|
+
{"version":3,"file":"string.js","sourceRoot":"","sources":["string.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 字面量類型工具\n * Literal Type Utilities\n *\n * 提供字串、數字、布林值轉換為字面量類型的工具\n * Provides utilities for converting strings, numbers, booleans to literal types\n */\n\n/** 允許轉換為字面量類型的基礎類型 / Base types allowed to convert to literal types */\nexport type ITSToStringLiteralAllowedType = string | number | boolean | bigint;\n\n/**\n * 將類型轉換為字面量類型 `${T}`\n * Convert type to literal type `${T}`\n *\n * @example\n * type Str = ITSToStringLiteral<'hello'>;\n * // type Str = \"hello\"\n *\n * @example\n * type Num = ITSToStringLiteral<42>;\n * // type Num = \"42\"\n */\nexport type ITSToStringLiteral<T extends ITSToStringLiteralAllowedType> = `${T}`\n\n/**\n * 原始類型與其字面量類型的聯合\n * Union of original type and its literal type\n *\n * T & `${T}`\n *\n * 適合用在 enum 或 string literal union,可以接受 enum 的字面量或基底類型\n * Suitable for enum or string literal union, can accept enum literal or base type\n *\n * @example\n * // 應用於 string literal union\n * type Status = 'active' | 'inactive' | 'pending';\n * type IStatus = ITSTypeAndStringLiteral<Status>;\n * // type IStatus = \"active\" | \"inactive\" | \"pending\" | string\n *\n * @example\n * // 應用於 enum\n * enum EnumPackageManager {\n * 'yarn' = 'yarn',\n * 'npm' = 'npm',\n * 'pnpm' = 'pnpm',\n * }\n * type IPackageManager = ITSTypeAndStringLiteral<EnumPackageManager>;\n * // type IPackageManager = EnumPackageManager | string\n *\n * @example\n * // 應用於 number,可接受數字或數字字串\n * type INumber = ITSTypeAndStringLiteral<number>;\n * // type INumber = number | `${number}`\n */\nexport type ITSTypeAndStringLiteral<T extends ITSToStringLiteralAllowedType> = T | ITSToStringLiteral<T>\n\n/**\n * 原始類型 S 與 T 的字面量類型的聯合\n * Union of original type S and literal type of T\n *\n * S & `${T}`\n *\n * @example\n * type Result = ITSAndStringLiteral<1 | 2 | 3, number>;\n * // type Result = number | \"1\" | \"2\" | \"3\"\n */\nexport type ITSAndStringLiteral<T extends ITSToStringLiteralAllowedType, S = string> = S | ITSToStringLiteral<T>\n\n/**\n * 原始類型 S、T 與 T 的字面量類型的聯合\n * Union of original types S, T and literal type of T\n *\n * S & T & `${T}`\n *\n * @example\n * type Result = ITSAndTypeAndStringLiteral<1 | 2 | 3, number>;\n * // type Result = number | \"1\" | \"2\" | \"3\"\n */\nexport type ITSAndTypeAndStringLiteral<T extends ITSToStringLiteralAllowedType, S = string> =\n\tS\n\t| ITSTypeAndStringLiteral<T>\n"]}
|
package/lib/helper/tuple.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tuple.js","sourceRoot":"","sources":["tuple.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 元組類型工具\n * Tuple Type Utilities\n
|
|
1
|
+
{"version":3,"file":"tuple.js","sourceRoot":"","sources":["tuple.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 元組類型工具\n * Tuple Type Utilities\n *\n * 提供元組相關的類型操作工具\n * Provides tuple-related type manipulation utilities\n */\n\n/**\n * 取得元組的數字索引鍵\n * Get numeric index keys of a tuple\n *\n * 回傳元組的所有數字索引(不包括陣列方法如 length、push 等)\n * Returns all numeric indices of the tuple (excluding array methods like length, push, etc.)\n *\n * @example\n * type Keys = ITSTupleKeys<[string, string, string]>;\n * // type Keys = \"0\" | \"1\" | \"2\"\n *\n * @see https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type\n */\nexport type ITSTupleKeys<T extends any[]> = Exclude<keyof T, keyof []>\n"]}
|
package/lib/helper/typeof.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeof.js","sourceRoot":"","sources":["typeof.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * 類型推断工具\n * Type Inference Utilities\n
|
|
1
|
+
{"version":3,"file":"typeof.js","sourceRoot":"","sources":["typeof.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * 類型推断工具\n * Type Inference Utilities\n *\n * 提供迭代器和其他類型相關的工具類型\n * Provides iterator and other type-related utility types\n *\n * Created by user on 2019/6/11.\n */\n\n/**\n * 迭代器類型\n * Iterator type\n *\n * 處理 Iterator 或 IteratorResult 類型,保留其原始結構\n * Handles Iterator or IteratorResult types, preserving their original structure\n *\n * @example\n * type LazyIterator = ITSIteratorLazy<Iterator<string>>;\n * // type LazyIterator = Iterator<string>\n */\nexport type ITSIteratorLazy<T extends Iterator<any> | IteratorResult<any>> =\n\tT extends IteratorResult<infer U> ? IteratorResult<U> :\n\t\tT extends Iterator<infer U> ? Iterator<U> :\n\t\t\tT\n\t;\n\n/**\n * 取得迭代器的值類型\n * Get the value type of an iterator\n *\n * 從 Iterator 或 IteratorResult 類型中提取值類型\n * Extracts the value type from Iterator or IteratorResult types\n *\n * @see https://stackoverflow.com/questions/49285864/is-there-a-valueof-similar-to-keyof-in-typescript\n *\n * @example\n * type IteratorValue = ITSTypeOfIterator<Iterator<string>>;\n * // type IteratorValue = string\n *\n * @example\n * type IteratorResultValue = ITSTypeOfIterator<IteratorResult<number>>;\n * // type IteratorResultValue = number\n */\nexport type ITSTypeOfIterator<T extends ITSIteratorLazy<any>> =\n\tT extends Iterator<infer U> ? U :\n\t\tT extends IteratorResult<infer U> ? U :\n\t\t\tany\n\t;\n"]}
|
package/lib/helper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["helper.ts"],"names":[],"mappings":"","sourcesContent":["import { ITSArrayListMaybeReadonly } from './type/base';\nimport { ITSAwaitedReturnType } from './helper/promise';\n\n
|
|
1
|
+
{"version":3,"file":"helper.js","sourceRoot":"","sources":["helper.ts"],"names":[],"mappings":"","sourcesContent":["import { ITSArrayListMaybeReadonly } from './type/base';\nimport { ITSAwaitedReturnType } from './helper/promise';\n\n/**\n * 複製當前函數的參數並返回新的值類型\n * Copy current function with Parameters and return to new value\n *\n * 不支援函數重載\n * Not support overload\n *\n * @example\n * declare function f(a: number): number\n * declare let c: ITSOverwriteReturnType<typeof f, string>;\n * // c = (a: number) => string\n */\nexport type ITSOverwriteReturnType<T extends (...args: any[]) => any, R extends unknown> =\n\t(...args: Parameters<T>) => R;\n\n/**\n * 將函數包裝為返回 PromiseLike 的版本\n * Wrap function to return PromiseLike version\n */\nexport type ITSWrapFunctionPromiseLike<T extends (...args: any[]) => any> =\n\t(...args: Parameters<T>) => PromiseLike<ITSAwaitedReturnType<T>>;\n/**\n * 將函數包裝為返回 Promise 的版本\n * Wrap function to return Promise version\n */\nexport type ITSWrapFunctionPromise<T extends (...args: any[]) => any> =\n\t(...args: Parameters<T>) => Promise<ITSAwaitedReturnType<T>>;\n\n/**\n * 擴展類型檢查:從 T 中提取屬於 U 的部分\n * Extend type check: extract parts of T that belong to U\n *\n * @deprecated 已棄用 / Deprecated\n */\nexport type ITSExtendsOf<T, U> = Extract<T, U>;\n\n/**\n * 取得陣列類型的數字索引鍵\n * Get numeric index keys of array type\n */\nexport type ITSKeyOfArray<T extends ITSArrayListMaybeReadonly<any>> = Exclude<keyof T, symbol | string>;\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filter.js","sourceRoot":"","sources":["filter.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 內部過濾工具(內部使用)\n * Internal Filter Utilities (Internal Use)\n
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["filter.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 內部過濾工具(內部使用)\n * Internal Filter Utilities (Internal Use)\n *\n * 提供內部使用的過濾類型工具\n * Provides internal filter type utilities\n */\n\nimport { ITSExtract2 } from '../helper/filter';\n\n/**\n * 根據匹配鍵過濾記錄(內部使用)\n * Filter record by matching keys (internal use)\n *\n * @internal\n */\ntype I_RecordOfMatchKey<M, T, K extends keyof M = keyof M> = {\n\t[P in K]: ITSExtract2<M[P], T, P>;\n};\n\n/**\n * 根據匹配值過濾記錄(內部使用)\n * Filter record by matching values (internal use)\n *\n * @internal\n */\ntype I_RecordOfMatchValue<M, T, K extends keyof M = keyof M> = {\n\t[P in K]: ITSExtract2<M[P], T>;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-literal.js","sourceRoot":"","sources":["string-literal.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 內部字串字面量邏輯工具(內部使用)\n * Internal String Literal Logic Utilities (Internal Use)\n
|
|
1
|
+
{"version":3,"file":"string-literal.js","sourceRoot":"","sources":["string-literal.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 內部字串字面量邏輯工具(內部使用)\n * Internal String Literal Logic Utilities (Internal Use)\n *\n * 提供內部使用的字串字面量邏輯判斷工具\n * Provides internal string literal logic detection utilities\n */\n\n/**\n * 檢測 T 是否為聯合類型(內部使用)\n * Detect if T is a union type (internal use)\n *\n * @internal\n *\n * @example\n * type Test1 = IsAUnion<'a' | 'b'>;\n * // type Test1 = true\n *\n * @example\n * type Test2 = IsAUnion<'a'>;\n * // type Test2 = false\n */\nexport type IsAUnion<T, Y = true, N = false, U = T> = U extends any\n\t? ([T] extends [U] ? N : Y)\n\t: never;\n\n/**\n * 檢測 T 是否為單一字串字面量(內部使用)\n * Detect if T is a single string literal (internal use)\n *\n * @internal\n *\n * @example\n * type Test1 = IsASingleStringLiteral<'hello'>;\n * // type Test1 = true\n *\n * @example\n * type Test2 = IsASingleStringLiteral<'a' | 'b'>;\n * // type Test2 = false\n *\n * @example\n * type Test3 = IsASingleStringLiteral<string>;\n * // type Test3 = false\n */\nexport type IsASingleStringLiteral<\n\tT extends string,\n\tY = true,\n\tN = false\n> = string extends T ? N : [T] extends [never] ? N : IsAUnion<T, N, Y>;\n"]}
|
package/lib/logic/any.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"any.js","sourceRoot":"","sources":["any.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * Any 類型判斷工具\n * Any Type Detection Utilities\n
|
|
1
|
+
{"version":3,"file":"any.js","sourceRoot":"","sources":["any.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * Any 類型判斷工具\n * Any Type Detection Utilities\n *\n * 提供檢測類型是否為 any 的工具\n * Provides utilities for detecting if a type is any\n *\n * @see https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360\n */\n\n/**\n * 檢測類型是否為 any\n * Detect if a type is any\n *\n * 利用 any 與任何類型交叉都會得到 any 的特性來檢測\n * Uses the fact that any intersected with any type still results in any\n *\n * @example\n * type Test1 = ITSLogicIsAny<any>;\n * // type Test1 = true\n *\n * @example\n * type Test2 = ITSLogicIsAny<string>;\n * // type Test2 = false\n */\nexport type ITSLogicIsAny<T, Y = true, N = false> = 0 extends (1 & T) ? Y : N\n\n/**\n * 檢測類型是否不為 any\n * Detect if a type is not any\n *\n * @example\n * type Test1 = ITSLogicNotAny<any>;\n * // type Test1 = false\n *\n * @example\n * type Test2 = ITSLogicNotAny<string>;\n * // type Test2 = true\n */\nexport type ITSLogicNotAny<T, Y = true, N = false> = ITSLogicIsAny<T, N, Y>\n"]}
|
package/lib/logic/never.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"never.js","sourceRoot":"","sources":["never.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * Never 類型判斷工具\n * Never Type Detection Utilities\n
|
|
1
|
+
{"version":3,"file":"never.js","sourceRoot":"","sources":["never.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * Never 類型判斷工具\n * Never Type Detection Utilities\n *\n * 提供檢測類型是否為 never 的工具\n * Provides utilities for detecting if a type is never\n */\n\n/**\n * 檢測類型是否為 never\n * Detect if a type is never\n *\n * 利用 never 是所有類型的子類型特性來檢測\n * Uses the fact that never is a subtype of all types\n *\n * @example\n * type Test1 = ITSLogicIsNever<never>;\n * // type Test1 = true\n *\n * @example\n * type Test2 = ITSLogicIsNever<string>;\n * // type Test2 = false\n */\nexport type ITSLogicIsNever<T, Y = true, N = false> = [T] extends [never] ? Y : N\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"empty.js","sourceRoot":"","sources":["empty.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"empty.js","sourceRoot":"","sources":["empty.ts"],"names":[],"mappings":"","sourcesContent":["import { ITSEmptyRecord } from '../../type/record/empty';\n\nexport type ITSLogicIsEmptyRecord<T, Y = true, N = false> = T extends ITSEmptyRecord ? Y : N\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 聯合類型邏輯工具\n * Union Type Logic Utilities\n
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 聯合類型邏輯工具\n * Union Type Logic Utilities\n *\n * 提供聯合類型相關的邏輯判斷工具\n * Provides union type-related logic detection utilities\n */\n\nimport { ITSUnionToIntersection } from '../../helper/intersection';\nimport { ITSLogicIsNever } from '../never';\n\n/**\n * 檢測類型是否為聯合類型\n * Detect if a type is a union type\n *\n * @example\n * type Test1 = ITSLogicIsUnion<string | number>;\n * // type Test1 = true\n *\n * @example\n * type Test2 = ITSLogicIsUnion<string>;\n * // type Test2 = false\n */\nexport type ITSLogicIsUnion<T, Y = true, N = false> = [T] extends [ITSUnionToIntersection<T>] ? N : Y\n\n/**\n * 檢測類型是否為單一非聯合類型\n * Detect if a type is a single non-union type\n *\n * @see https://stackoverflow.com/a/49982981/4563339\n *\n * @example\n * type Test1 = ITSLogicIsSingleNonUnion01<'' | '4' | any, string>;\n * // type Test1 = false (因為是聯合類型)\n *\n * @example\n * type Test2 = ITSLogicIsSingleNonUnion01<'' & '4' & any, string>;\n * // type Test2 = false (因為是交集類型)\n *\n * @example\n * type Test3 = ITSLogicIsSingleNonUnion01<'', string>;\n * // type Test3 = true (因為是單一類型)\n */\nexport type ITSLogicIsSingleNonUnion01<\n\tT,\n\tU extends any,\n\tY = true,\n\tN = false\n> = U extends T ?\n\tN : ITSLogicIsNever<T, N, ITSLogicIsUnion<T, N, Y>>\n\t;\n"]}
|
package/lib/type/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["base.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 基礎類型定義\n * Base Type Definitions\n
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["base.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 基礎類型定義\n * Base Type Definitions\n *\n * 提供常用的基礎類型別名和工具類型\n * Provides commonly used base type aliases and utility types\n */\n\nimport { ITSTypeFunction } from '../generic';\n\n/**\n * 陣列類型:可讀寫陣列或唯讀陣列\n * Array type: writable array or readonly array\n *\n * @example\n * type StringList = ITSArrayListMaybeReadonly<string>;\n * // type StringList = string[] | readonly string[]\n */\nexport type ITSArrayListMaybeReadonly<T> = T[] | readonly T[];\n\n/**\n * 鍵的類型:符號、字串或數字\n * Key types: symbol, string, or number\n *\n * @example\n * type Keys = ITSKeys;\n * // type Keys = symbol | string | number\n */\nexport type ITSKeys = symbol | string | number;\n\n/**\n * 建構函數類型\n * Constructor type\n *\n * @example\n * type MyConstructor = ITSConstructorLike<MyClass>;\n * // type MyConstructor = new (...args: any) => MyClass\n */\nexport type ITSConstructorLike<T extends any = any> = new(...args: any) => T;\n\n/**\n * 值或陣列:單一值或其陣列\n * Value or array: single value or array of that value\n *\n * @example\n * type StringOrArray = ITSValueOrArray<string>;\n * // type StringOrArray = string | string[]\n */\nexport type ITSValueOrArray<T> = T | T[];\n\n/**\n * 值或可能唯讀的陣列:單一值、可讀寫陣列或唯讀陣列\n * Value or possibly readonly array: single value, writable array, or readonly array\n *\n * @example\n * type StringOrList = ITSValueOrArrayMaybeReadonly<string>;\n * // type StringOrList = string | string[] | readonly string[]\n */\nexport type ITSValueOrArrayMaybeReadonly<T> = T | ITSArrayListMaybeReadonly<T>;\n\n/**\n * 屬性鍵類型:字串或符號\n * Property key type: string or symbol\n *\n * @example\n * type PropKey = ITSPropertyKey;\n * // type PropKey = string | symbol\n */\nexport type ITSPropertyKey = string | symbol;\n\n/**\n * 屬性鍵或索引類型:字串、符號或數字\n * Property key or index type: string, symbol, or number\n *\n * 適用於物件屬性存取與陣列索引的聯合類型\n * Suitable for union type covering object property access and array index access\n *\n * @see {@link ITSPropertyKey} - 僅字串或符號(不含數字索引)\n *\n * @example\n * type KeyOrIdx = ITSPropertyKeyOrIndex;\n * // type KeyOrIdx = string | symbol | number\n */\nexport type ITSPropertyKeyOrIndex = ITSPropertyKey | number;\n\n/**\n * 任意函數類型\n * Any function type\n *\n * @example\n * type AnyFunc = ITSAnyFunction;\n * // type AnyFunc = (...args: any[]) => any\n */\nexport type ITSAnyFunction = ITSTypeFunction<any>;\n\n/**\n * 基本原始類型:數字、字串或布林值\n * Basic primitive types: number, string, or boolean\n *\n * @example\n * type Primitive = ITSBasicPrimitive;\n * // type Primitive = number | string | boolean\n */\nexport type ITSBasicPrimitive = number | string | boolean;\n\n/**\n * 可為空的原始類型:null 或 undefined\n * Nullable primitive types: null or undefined\n *\n * @example\n * type Nullish = ITSNullPrimitive;\n * // type Nullish = null | undefined\n */\nexport type ITSNullPrimitive = null | undefined;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["generator.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["generator.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * TypeScript Generator 類型\n * TypeScript Generator type\n *\n * 代表 JavaScript Generator 物件的類型\n * Represents the type of a JavaScript Generator object\n *\n * @typeParam T - 生成器yield的值類型 / Type of value yielded by the generator\n * @typeParam TReturn - 生成器完成時返回的類型 / Type returned when generator completes\n * @typeParam TNext - 傳遞給生成器next()方法的參數類型 / Type of argument passed to generator's next() method\n */\nexport type ITSGenerator<T = unknown, TReturn = T, TNext = T> = Generator<T, TReturn, TNext>;\n\n/**\n * TypeScript AsyncGenerator 類型\n * TypeScript AsyncGenerator type\n *\n * 代表 JavaScript AsyncGenerator 物件的類型\n * Represents the type of a JavaScript AsyncGenerator object\n *\n * @typeParam T - 生成器yield的值類型 / Type of value yielded by the async generator\n * @typeParam TReturn - 生成器完成時返回的類型 / Type returned when async generator completes\n * @typeParam TNext - 傳遞給生成器next()方法的參數類型 / Type of argument passed to async generator's next() method\n */\nexport type ITSAsyncGenerator<T = unknown, TReturn = T, TNext = T> = AsyncGenerator<T, TReturn, TNext>;\n"]}
|
package/lib/type/iterator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterator.js","sourceRoot":"","sources":["iterator.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 迭代器類型定義\n * Iterator Type Definitions\n
|
|
1
|
+
{"version":3,"file":"iterator.js","sourceRoot":"","sources":["iterator.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 迭代器類型定義\n * Iterator Type Definitions\n *\n * 提供 Iterator 和 IteratorResult 的類型定義\n * Provides Iterator and IteratorResult type definitions\n */\n\n/**\n * Iterator 類型\n * Iterator type\n *\n * @example\n * const iterator: ITSIterator<string> = {\n * next() { return { done: false, value: 'test' }; }\n * };\n */\nexport type ITSIterator<T, TReturn = void, TNext = undefined> = Iterator<T, TReturn, TNext>;\n\n/**\n * IteratorResult 類型\n * IteratorResult type\n *\n * @example\n * const result: ITSIteratorResult<string> = { done: false, value: 'test' };\n */\nexport type ITSIteratorResult<T, TReturn = void> = IteratorResult<T, TReturn>;\n"]}
|
package/lib/type/promise.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise.js","sourceRoot":"","sources":["promise.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * Promise 類型工具\n * Promise Type Utilities\n
|
|
1
|
+
{"version":3,"file":"promise.js","sourceRoot":"","sources":["promise.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * Promise 類型工具\n * Promise Type Utilities\n *\n * 提供 Promise 相關的類型操作工具\n * Provides Promise-related type manipulation utilities\n *\n * Created by user on 2019/6/11.\n */\n\n/**\n * 延遲物件類型:將物件的所有屬性包裝為 Promise\n * Deferred object type: wraps all properties of an object in Promise\n *\n * 保持相同的屬性名稱,但將值類型包裝為 Promise\n * Keeps the same property names, but wraps value types in Promise\n *\n * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html\n *\n * @example\n * interface User {\n * id: number;\n * name: string;\n * }\n * type DeferredUser = ITSDeferred<User>;\n * // type DeferredUser = { id: Promise<number>; name: Promise<string>; }\n */\nexport type ITSDeferred<T> = {\n\t[P in keyof T]: Promise<T[P]>;\n};\n\n/**\n * Promise 解決結果介面\n * Promise fulfilled result interface\n *\n * 表示 Promise 已成功解決\n * Represents a promise that has been successfully resolved\n *\n * @example\n * const fulfilled: ITSPromiseFulfilledResult<string> = {\n * status: \"fulfilled\",\n * value: \"success\"\n * };\n */\nexport interface ITSPromiseFulfilledResult<T>\n{\n\t/** 解決狀態 / Fulfilled status */\n\tstatus: \"fulfilled\";\n\t/** 解決值 / Resolved value */\n\tvalue: T;\n\t/** 永不存在的拒絕原因 / Reason that never exists */\n\treason?: never;\n}\n\n/**\n * Promise 拒絕結果介面\n * Promise rejected result interface\n *\n * 表示 Promise 被拒絕\n * Represents a promise that has been rejected\n *\n * @example\n * const rejected: ITSPromiseRejectedResult<Error> = {\n * status: \"rejected\",\n * reason: new Error(\"failed\")\n * };\n */\nexport interface ITSPromiseRejectedResult<E = any>\n{\n\t/** 拒絕狀態 / Rejected status */\n\tstatus: \"rejected\";\n\t/** 拒絕原因 / Rejection reason */\n\treason: E;\n\t/** 永不存在的解決值 / Value that never exists */\n\tvalue?: never;\n}\n\n/**\n * Promise settled 結果類型:解決或拒絕結果的聯合類型\n * Promise settled result type: union of fulfilled or rejected result\n *\n * @example\n * const result: ITSPromiseSettledResult<string> = Math.random() > 0.5\n * ? { status: \"fulfilled\", value: \"success\" }\n * : { status: \"rejected\", reason: new Error(\"failed\") };\n */\nexport type ITSPromiseSettledResult<T, E = any> = ITSPromiseFulfilledResult<T> | ITSPromiseRejectedResult<E>;\n"]}
|
package/lib/type/proxy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["proxy.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * Proxy 類型工具\n * Proxy Type Utilities\n
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["proxy.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * Proxy 類型工具\n * Proxy Type Utilities\n *\n * 提供 Proxy 相關的類型操作工具\n * Provides Proxy-related type manipulation utilities\n */\n\n/**\n * 將物件的屬性包裝為 Proxy\n * Wrap properties of object with Proxy\n *\n * 將每個屬性轉換為具有 getter 和 setter 的物件\n * Converts each property to an object with getter and setter\n *\n * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html\n *\n * @example\n * interface User { name: string; age: number; }\n * type ProxifiedUser = ITSProxify<User>;\n * // type ProxifiedUser = {\n * // name: { get(): string; set(v: string): void };\n * // age: { get(): number; set(v: number): void };\n * // }\n */\nexport type ITSProxify<T> = {\n\t[P in keyof T]: { get(): T[P]; set(v: T[P]): void }\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"empty.js","sourceRoot":"","sources":["empty.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * 空記錄類型工具\n * Empty Record Type Utilities\n
|
|
1
|
+
{"version":3,"file":"empty.js","sourceRoot":"","sources":["empty.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * 空記錄類型工具\n * Empty Record Type Utilities\n *\n * 提供空記錄類型的工具\n * Provides empty record type utilities\n *\n * @see https://juejin.cn/post/7116327095118069773\n */\n\n/**\n * 指定鍵集合的空記錄\n * Empty record with specified key set\n *\n * 建立一個具有指定鍵集合但所有值都為 never 的記錄類型\n * Creates a record type with specified key set but all values are never\n *\n * @example\n * type EmptyByKeys = ITSEmptyRecordByKeys<'a' | 'b'>;\n * // type EmptyByKeys = { a: never; b: never; }\n */\nexport type ITSEmptyRecordByKeys<K extends PropertyKey> = Record<K, never>;\n\n/**\n * 空記錄(接受任何鍵,但值都為 never)\n * Empty record (accepts any key, but values are never)\n *\n * @example\n * type Empty = ITSEmptyRecord;\n * // type Empty = Record<PropertyKey, never>\n *\n * @see https://juejin.cn/post/7116327095118069773\n */\nexport type ITSEmptyRecord = ITSEmptyRecordByKeys<PropertyKey>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enum.js","sourceRoot":"","sources":["enum.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 列舉類型定義\n * Enum Type Definitions\n
|
|
1
|
+
{"version":3,"file":"enum.js","sourceRoot":"","sources":["enum.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 列舉類型定義\n * Enum Type Definitions\n *\n * 提供列舉類型的相關類型定義\n * Provides enum type related type definitions\n */\n\nimport { ITSReadonlyRecord } from './readonly';\nimport { ITSTypeAndStringLiteral } from '../../helper/string';\n\n/**\n * 列舉類型\n * Enum type\n *\n * 支援字串列舉、數字列舉或兩者的組合\n * Supports string enums, number enums, or a combination of both\n *\n * @example\n * // 字串列舉\n * enum EnumString { A = 'a', B = 'b' }\n * // 數字列舉\n * enum EnumNumber { A = 1, B = 2 }\n * // 混合列舉\n * enum EnumMixed { A = 'a', B = 1 }\n */\nexport type ITSEnumLike<K extends string = string, V extends string | number = string | number> =\n\tITSReadonlyRecord<K, V>\n\t| (V extends number ? ITSNumberEnumLikeReverse<K, Exclude<V, string>> : ITSEnumLikeReverseExcludeNumber);\n\n/**\n * 字串列舉類型\n * String enum type\n *\n * @example\n * enum EnumString { A = 'a', B = 'b' }\n * type T = ITSStringEnumLike<EnumString>;\n */\nexport type ITSStringEnumLike<K extends string = string, V extends string = string> =\n\t(ITSReadonlyRecord<K, V> | ITSStringEnumLikeReverse<K, V>)\n\t& ITSEnumLikeReverseExcludeNumber;\n\n/**\n * 數字列舉類型\n * Number enum type\n *\n * @example\n * enum EnumNumber { A = 1, B = 2 }\n * type T = ITSNumberEnumLike<EnumNumber>;\n */\nexport type ITSNumberEnumLike<K extends string = string, V extends number = number> =\n\tITSReadonlyRecord<K, V>\n\t| ITSNumberEnumLikeReverse<K, V>;\n\n/**\n * 字串列舉反向映射類型(內部使用)\n * String enum reverse mapping type (internal use)\n *\n * @internal\n */\nexport type ITSStringEnumLikeReverse<K extends string = string, V extends string = string> =\n\tITSReadonlyRecord<V, K>;\n\n/**\n * 數字列舉反向映射類型(內部使用)\n * Number enum reverse mapping type (internal use)\n *\n * @see https://github.com/microsoft/TypeScript/issues/51105\n *\n * @internal\n */\nexport type ITSNumberEnumLikeReverse<K extends string = string, V extends number = number> = ITSReadonlyRecord<Exclude<ITSTypeAndStringLiteral<V>, K>, K>;\n\n/**\n * 排除數字的列舉反向映射(內部使用)\n * Enum reverse mapping excluding number (internal use)\n *\n * @internal\n */\nexport type ITSEnumLikeReverseExcludeNumber = ITSReadonlyRecord<number, void | never>;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"partial.js","sourceRoot":"","sources":["partial.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 記錄部分類型工具\n * Record Partial Type Utilities\n
|
|
1
|
+
{"version":3,"file":"partial.js","sourceRoot":"","sources":["partial.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 記錄部分類型工具\n * Record Partial Type Utilities\n *\n * 提供可選和必填記錄類型的工具\n * Provides optional and required record type utilities\n */\n\n/**\n * 可選的記錄類型\n * Optional record type\n *\n * 類似 Partial,但使用指定的鍵集合\n * Similar to Partial, but uses a specified key set\n *\n * @example\n * type PartialUser = ITSPartialRecord<'name' | 'age', string>;\n * // type PartialUser = { name?: string; age?: string; }\n */\nexport type ITSPartialRecord<K extends keyof any, T> = {\n\t[P in K]?: T;\n};\n\n/**\n * 必填的記錄類型\n * Required record type\n *\n * 類似 Required,但使用指定的鍵集合\n * Similar to Required, but uses a specified key set\n *\n * @example\n * type RequiredUser = ITSRequireRecord<'name' | 'age', string>;\n * // type RequiredUser = { name: string; age: string; }\n */\nexport type ITSRequireRecord<K extends keyof any, T> = {\n\t[P in K]-?: T;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readonly.js","sourceRoot":"","sources":["readonly.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 記錄唯讀類型工具\n * Record Readonly Type Utilities\n
|
|
1
|
+
{"version":3,"file":"readonly.js","sourceRoot":"","sources":["readonly.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 記錄唯讀類型工具\n * Record Readonly Type Utilities\n *\n * 提供唯讀和可讀寫記錄類型的工具\n * Provides readonly and writable record type utilities\n */\n\n/**\n * 唯讀記錄類型\n * Readonly record type\n *\n * 將指定鍵集合的所有屬性設為唯讀\n * Makes all properties of the specified key set readonly\n *\n * @example\n * type ReadonlyUser = ITSReadonlyRecord<'name' | 'age', string>;\n * // type ReadonlyUser = { readonly name: string; readonly age: string; }\n */\nexport type ITSReadonlyRecord<K extends keyof any, T> = {\n\treadonly [P in K]: T;\n};\n\n/**\n * 可讀寫記錄類型\n * Writable record type\n *\n * 將指定鍵集合的所有屬性設為可讀寫(移除 readonly)\n * Makes all properties of the specified key set writable (removes readonly)\n *\n * @example\n * type WritableUser = ITSWriteableRecord<'name' | 'age', string>;\n * // type WritableUser = { name: string; age: string; }\n */\nexport type ITSWriteableRecord<K extends keyof any, T> = {\n\t-readonly [P in K]: T;\n};\n"]}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { ITSKeyOfUnion, ITSValueOfUnion } from "../../helper/key-value";
|
|
2
|
+
import { ITSPartialPick, ITSRequiredPick } from "../record";
|
|
3
|
+
/**
|
|
4
|
+
* Makes the selected properties optional while preserving
|
|
5
|
+
* the structure of each union member.
|
|
6
|
+
*
|
|
7
|
+
* This is the distributive Union version.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* type T =
|
|
11
|
+
* | { type: "a"; value: number }
|
|
12
|
+
* | { type: "b"; text: string };
|
|
13
|
+
*
|
|
14
|
+
* type Result = ITSPartialPickUnion<T>;
|
|
15
|
+
* // {
|
|
16
|
+
* // type?: "a";
|
|
17
|
+
* // value?: number;
|
|
18
|
+
* // } | {
|
|
19
|
+
* // type?: "b";
|
|
20
|
+
* // text?: string;
|
|
21
|
+
* // }
|
|
22
|
+
*/
|
|
23
|
+
export type ITSPartialPickUnion<T, K extends ITSKeyOfUnion<T> = ITSKeyOfUnion<T>> = T extends any ? {
|
|
24
|
+
[P in K & keyof T]?: T[P];
|
|
25
|
+
} : never;
|
|
26
|
+
/**
|
|
27
|
+
* Makes the selected properties required while preserving
|
|
28
|
+
* the structure of each union member.
|
|
29
|
+
*
|
|
30
|
+
* This is the distributive Union version.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* type T =
|
|
34
|
+
* | { type: "a"; value?: number }
|
|
35
|
+
* | { type: "b"; text?: string };
|
|
36
|
+
*
|
|
37
|
+
* type Result = ITSRequiredPickUnion<T>;
|
|
38
|
+
* // {
|
|
39
|
+
* // type: "a";
|
|
40
|
+
* // value: number;
|
|
41
|
+
* // } | {
|
|
42
|
+
* // type: "b";
|
|
43
|
+
* // text: string;
|
|
44
|
+
* // }
|
|
45
|
+
*/
|
|
46
|
+
export type ITSRequiredPickUnion<T, K extends ITSKeyOfUnion<T> = ITSKeyOfUnion<T>> = T extends any ? {
|
|
47
|
+
[P in K & keyof T]-?: T[P];
|
|
48
|
+
} : never;
|
|
49
|
+
/**
|
|
50
|
+
* Makes the selected properties optional and flattens
|
|
51
|
+
* all properties from every union member into a single object type.
|
|
52
|
+
*
|
|
53
|
+
* Unlike ITSPartialPickUnion, this does not preserve the
|
|
54
|
+
* individual union-member structure.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* type T =
|
|
58
|
+
* | { type: "a"; value: number }
|
|
59
|
+
* | { type: "b"; text: string };
|
|
60
|
+
*
|
|
61
|
+
* type Result = ITSPartialPickUnionFlat<T>;
|
|
62
|
+
* // {
|
|
63
|
+
* // type?: "a" | "b";
|
|
64
|
+
* // value?: number;
|
|
65
|
+
* // text?: string;
|
|
66
|
+
* // }
|
|
67
|
+
*/
|
|
68
|
+
export type ITSPartialPickUnionFlat<T, K extends ITSKeyOfUnion<T> = ITSKeyOfUnion<T>> = {
|
|
69
|
+
[P in K]?: ITSValueOfUnion<T, P>;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Makes the selected properties required and flattens
|
|
73
|
+
* all members of a union into a single object type.
|
|
74
|
+
*
|
|
75
|
+
* Note: this utility intentionally makes every selected property
|
|
76
|
+
* required. For a natural flattened representation that preserves
|
|
77
|
+
* whether a property exists in every member, use a dedicated
|
|
78
|
+
* flat-base utility.
|
|
79
|
+
*/
|
|
80
|
+
export type ITSRequiredPickUnionFlat<T, K extends ITSKeyOfUnion<T> = ITSKeyOfUnion<T>> = {
|
|
81
|
+
[P in K]-?: ITSValueOfUnion<T, P>;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Makes the specified properties required for each member
|
|
85
|
+
* of a union while preserving the union-member structure.
|
|
86
|
+
*
|
|
87
|
+
* Other properties are preserved unchanged.
|
|
88
|
+
*/
|
|
89
|
+
export type ITSRequiredWithUnion<T, K extends ITSKeyOfUnion<T>> = T extends any ? K extends keyof T ? Omit<T, K> & ITSRequiredPick<T, K> : T : never;
|
|
90
|
+
/**
|
|
91
|
+
* Makes the specified properties optional for each member
|
|
92
|
+
* of a union while preserving the union-member structure.
|
|
93
|
+
*
|
|
94
|
+
* Other properties are preserved unchanged.
|
|
95
|
+
*/
|
|
96
|
+
export type ITSPartialWithUnion<T, K extends ITSKeyOfUnion<T>> = T extends any ? K extends keyof T ? Omit<T, K> & ITSPartialPick<T, K> : T : never;
|
|
97
|
+
export type ITSUnionFlat<T> = {
|
|
98
|
+
[P in ITSKeyOfUnionRequired<T>]-?: ITSValueOfUnion<T, P>;
|
|
99
|
+
} & {
|
|
100
|
+
[P in ITSKeyOfUnionOptional<T>]?: ITSValueOfUnion<T, P>;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Checks whether K is required in every member of T.
|
|
104
|
+
*/
|
|
105
|
+
export type ITSIsRequiredInUnion<T, K extends ITSKeyOfUnion<T>> = false extends (T extends unknown ? K extends keyof T ? {} extends Pick<T, K> ? false : true : false : never) ? false : true;
|
|
106
|
+
/**
|
|
107
|
+
* Gets keys that are required in every member of T.
|
|
108
|
+
*/
|
|
109
|
+
export type ITSKeyOfUnionRequired<T> = {
|
|
110
|
+
[K in ITSKeyOfUnion<T>]: ITSIsRequiredInUnion<T, K> extends true ? K : never;
|
|
111
|
+
}[ITSKeyOfUnion<T>];
|
|
112
|
+
/**
|
|
113
|
+
* Gets keys that are not required in every member of T.
|
|
114
|
+
*/
|
|
115
|
+
export type ITSKeyOfUnionOptional<T> = Exclude<ITSKeyOfUnion<T>, ITSKeyOfUnionRequired<T>>;
|
|
116
|
+
/**
|
|
117
|
+
* Makes the specified properties required and flattens
|
|
118
|
+
* all members of a union into a single object type.
|
|
119
|
+
*
|
|
120
|
+
* Other properties from all union members are preserved as
|
|
121
|
+
* optional properties because they may not exist in every member.
|
|
122
|
+
*/
|
|
123
|
+
export type ITSPartialWithUnionFlat<T, K extends ITSKeyOfUnion<T>> = Omit<ITSUnionFlat<T>, K> & {
|
|
124
|
+
[P in K]?: ITSValueOfUnion<T, P>;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Makes the specified properties optional and flattens
|
|
128
|
+
* all members of a union into a single object type.
|
|
129
|
+
*
|
|
130
|
+
* Other properties from all union members are preserved as
|
|
131
|
+
* optional properties because they may not exist in every member.
|
|
132
|
+
*/
|
|
133
|
+
export type ITSRequiredWithUnionFlat<T, K extends ITSKeyOfUnion<T>> = Omit<ITSUnionFlat<T>, K> & {
|
|
134
|
+
[P in K]-?: ITSValueOfUnion<T, P>;
|
|
135
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
ITSPartialPick / ITSRequiredPick
|
|
4
|
+
└─ 一般 Object
|
|
5
|
+
└─ keyof T
|
|
6
|
+
|
|
7
|
+
ITSPartialPickUnion / ITSRequiredPickUnion
|
|
8
|
+
└─ Union
|
|
9
|
+
└─ 保留 A | B 結構
|
|
10
|
+
└─ distributive conditional type
|
|
11
|
+
|
|
12
|
+
ITSPartialPickUnionFlat / ITSRequiredPickUnionFlat
|
|
13
|
+
└─ UnionFlat
|
|
14
|
+
└─ A | B → 單一 Object
|
|
15
|
+
└─ ITSKeyOfUnion + ITSValueOfUnion
|
|
16
|
+
|
|
17
|
+
PartialWith
|
|
18
|
+
→ 修改 K,保留 Object
|
|
19
|
+
|
|
20
|
+
PartialWithUnion
|
|
21
|
+
→ 修改 K,保留 A | B
|
|
22
|
+
|
|
23
|
+
PartialWithUnionFlat
|
|
24
|
+
→ Flatten A | B,再只修改 K
|
|
25
|
+
*/
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
//# sourceMappingURL=union.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"union.js","sourceRoot":"","sources":["union.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;EAuBE","sourcesContent":["/*\r\nITSPartialPick / ITSRequiredPick\r\n└─ 一般 Object\r\n └─ keyof T\r\n\r\nITSPartialPickUnion / ITSRequiredPickUnion\r\n└─ Union\r\n └─ 保留 A | B 結構\r\n └─ distributive conditional type\r\n\r\nITSPartialPickUnionFlat / ITSRequiredPickUnionFlat\r\n└─ UnionFlat\r\n └─ A | B → 單一 Object\r\n └─ ITSKeyOfUnion + ITSValueOfUnion\r\n\r\nPartialWith\r\n\t→ 修改 K,保留 Object\r\n\r\nPartialWithUnion\r\n\t→ 修改 K,保留 A | B\r\n\r\nPartialWithUnionFlat\r\n\t→ Flatten A | B,再只修改 K\r\n*/\r\n\r\nimport { ITSKeyOfUnion, ITSValueOfUnion } from \"../../helper/key-value\";\r\nimport { ITSPartialPick, ITSPartialWith, ITSRequiredPick, ITSRequiredWith } from \"../record\";\r\n\r\n/**\r\n * Makes the selected properties optional while preserving\r\n * the structure of each union member.\r\n *\r\n * This is the distributive Union version.\r\n *\r\n * @example\r\n * type T =\r\n * | { type: \"a\"; value: number }\r\n * | { type: \"b\"; text: string };\r\n *\r\n * type Result = ITSPartialPickUnion<T>;\r\n * // {\r\n * // type?: \"a\";\r\n * // value?: number;\r\n * // } | {\r\n * // type?: \"b\";\r\n * // text?: string;\r\n * // }\r\n */\r\nexport type ITSPartialPickUnion<\r\n\tT,\r\n\tK extends ITSKeyOfUnion<T> = ITSKeyOfUnion<T>\r\n> = T extends any\r\n\t? {\r\n\t\t[P in K & keyof T]?: T[P];\r\n\t}\r\n\t: never;\r\n\r\n/**\r\n * Makes the selected properties required while preserving\r\n * the structure of each union member.\r\n *\r\n * This is the distributive Union version.\r\n *\r\n * @example\r\n * type T =\r\n * | { type: \"a\"; value?: number }\r\n * | { type: \"b\"; text?: string };\r\n *\r\n * type Result = ITSRequiredPickUnion<T>;\r\n * // {\r\n * // type: \"a\";\r\n * // value: number;\r\n * // } | {\r\n * // type: \"b\";\r\n * // text: string;\r\n * // }\r\n */\r\nexport type ITSRequiredPickUnion<\r\n\tT,\r\n\tK extends ITSKeyOfUnion<T> = ITSKeyOfUnion<T>\r\n> = T extends any\r\n\t? {\r\n\t\t[P in K & keyof T]-?: T[P];\r\n\t}\r\n\t: never;\r\n\r\n/**\r\n * Makes the selected properties optional and flattens\r\n * all properties from every union member into a single object type.\r\n *\r\n * Unlike ITSPartialPickUnion, this does not preserve the\r\n * individual union-member structure.\r\n *\r\n * @example\r\n * type T =\r\n * | { type: \"a\"; value: number }\r\n * | { type: \"b\"; text: string };\r\n *\r\n * type Result = ITSPartialPickUnionFlat<T>;\r\n * // {\r\n * // type?: \"a\" | \"b\";\r\n * // value?: number;\r\n * // text?: string;\r\n * // }\r\n */\r\nexport type ITSPartialPickUnionFlat<\r\n\tT,\r\n\tK extends ITSKeyOfUnion<T> = ITSKeyOfUnion<T>\r\n> = {\r\n\t[P in K]?: ITSValueOfUnion<T, P>;\r\n};\r\n\r\n/**\r\n * Makes the selected properties required and flattens\r\n * all members of a union into a single object type.\r\n *\r\n * Note: this utility intentionally makes every selected property\r\n * required. For a natural flattened representation that preserves\r\n * whether a property exists in every member, use a dedicated\r\n * flat-base utility.\r\n */\r\nexport type ITSRequiredPickUnionFlat<\r\n\tT,\r\n\tK extends ITSKeyOfUnion<T> = ITSKeyOfUnion<T>\r\n> = {\r\n\t[P in K]-?: ITSValueOfUnion<T, P>;\r\n};\r\n\r\n// ---------------\r\n\r\n/**\r\n * Makes the specified properties required for each member\r\n * of a union while preserving the union-member structure.\r\n *\r\n * Other properties are preserved unchanged.\r\n */\r\nexport type ITSRequiredWithUnion<\r\n\tT,\r\n\tK extends ITSKeyOfUnion<T>\r\n> = T extends any\r\n\t? K extends keyof T\r\n\t\t? Omit<T, K> & ITSRequiredPick<T, K>\r\n\t\t: T\r\n\t: never;\r\n\r\n/**\r\n * Makes the specified properties optional for each member\r\n * of a union while preserving the union-member structure.\r\n *\r\n * Other properties are preserved unchanged.\r\n */\r\nexport type ITSPartialWithUnion<\r\n\tT,\r\n\tK extends ITSKeyOfUnion<T>\r\n> = T extends any\r\n\t? K extends keyof T\r\n\t\t? Omit<T, K> & ITSPartialPick<T, K>\r\n\t\t: T\r\n\t: never;\r\n\r\nexport type ITSUnionFlat<T> = {\r\n\t[P in ITSKeyOfUnionRequired<T>]-?: ITSValueOfUnion<T, P>;\r\n} & {\r\n\t[P in ITSKeyOfUnionOptional<T>]?: ITSValueOfUnion<T, P>;\r\n};\r\n\r\n/**\r\n * Checks whether K is required in every member of T.\r\n */\r\nexport type ITSIsRequiredInUnion<\r\n T,\r\n K extends ITSKeyOfUnion<T>\r\n> = false extends (\r\n T extends unknown\r\n ? K extends keyof T\r\n ? {} extends Pick<T, K>\r\n ? false\r\n : true\r\n : false\r\n : never\r\n)\r\n ? false\r\n : true;\r\n\r\n/**\r\n * Gets keys that are required in every member of T.\r\n */\r\nexport type ITSKeyOfUnionRequired<T> = {\r\n [K in ITSKeyOfUnion<T>]:\r\n ITSIsRequiredInUnion<T, K> extends true\r\n ? K\r\n : never;\r\n}[ITSKeyOfUnion<T>];\r\n\r\n/**\r\n * Gets keys that are not required in every member of T.\r\n */\r\nexport type ITSKeyOfUnionOptional<T> =\r\n Exclude<\r\n ITSKeyOfUnion<T>,\r\n ITSKeyOfUnionRequired<T>\r\n >;\r\n\r\n/**\r\n * Makes the specified properties required and flattens\r\n * all members of a union into a single object type.\r\n *\r\n * Other properties from all union members are preserved as\r\n * optional properties because they may not exist in every member.\r\n */\r\nexport type ITSPartialWithUnionFlat<\r\n T,\r\n K extends ITSKeyOfUnion<T>\r\n> = Omit<ITSUnionFlat<T>, K>\r\n & {\r\n [P in K]?: ITSValueOfUnion<T, P>;\r\n };\r\n\r\n/**\r\n * Makes the specified properties optional and flattens\r\n * all members of a union into a single object type.\r\n *\r\n * Other properties from all union members are preserved as\r\n * optional properties because they may not exist in every member.\r\n */\r\nexport type ITSRequiredWithUnionFlat<\r\n T,\r\n K extends ITSKeyOfUnion<T>\r\n> = Omit<ITSUnionFlat<T>, K>\r\n & {\r\n [P in K]-?: ITSValueOfUnion<T, P>;\r\n };"]}
|
package/lib/type/record.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* Created by user on 2019/6/11.
|
|
9
9
|
*/
|
|
10
10
|
import type { ITSKeyofBothDiff, ITSKeyofBothSame, ITSKeyofDiff, ITSKeyofSame } from '../helper/filter';
|
|
11
|
+
import { ITSLogicIsNever } from '../logic/never';
|
|
11
12
|
export type { ITSRequireRecord, ITSPartialRecord } from '../type/record/partial';
|
|
12
13
|
/**
|
|
13
14
|
* 取得兩個鍵集合的差異(已棄用)
|
|
@@ -116,25 +117,40 @@ export type ITSOverwrite<T, U> = Omit<T, keyof U> & U;
|
|
|
116
117
|
*/
|
|
117
118
|
export type ITSMergeBoth<T, U> = ITSPickBothDiff<T, U> & Pick<T | U, ITSKeyofBothSame<T, U>>;
|
|
118
119
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
120
|
+
* Makes the selected properties of a type required.
|
|
121
|
+
*
|
|
122
|
+
* This is the standard version and is intended for a single object type.
|
|
121
123
|
*
|
|
122
124
|
* @example
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
125
|
+
* type User = {
|
|
126
|
+
* name?: string;
|
|
127
|
+
* age?: number;
|
|
128
|
+
* };
|
|
129
|
+
*
|
|
130
|
+
* type Result = ITSRequiredPick<User, "name">;
|
|
131
|
+
* // {
|
|
132
|
+
* // name: string;
|
|
133
|
+
* // age?: number;
|
|
134
|
+
* // }
|
|
126
135
|
*/
|
|
127
136
|
export type ITSRequiredPick<T, K extends keyof T = keyof T> = {
|
|
128
137
|
[P in K]-?: T[P];
|
|
129
138
|
};
|
|
130
139
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
140
|
+
* Makes the selected properties of a type optional.
|
|
141
|
+
*
|
|
142
|
+
* This is the standard version and is intended for a single object type.
|
|
133
143
|
*
|
|
134
144
|
* @example
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
145
|
+
* type User = {
|
|
146
|
+
* name: string;
|
|
147
|
+
* age: number;
|
|
148
|
+
* };
|
|
149
|
+
*
|
|
150
|
+
* type Result = ITSPartialPick<User, "name">;
|
|
151
|
+
* // {
|
|
152
|
+
* // name?: string;
|
|
153
|
+
* // }
|
|
138
154
|
*/
|
|
139
155
|
export type ITSPartialPick<T, K extends keyof T = keyof T> = {
|
|
140
156
|
[P in K]?: T[P];
|
|
@@ -178,25 +194,17 @@ export type ITSPickExtra2<T, PK extends keyof T, RK extends Exclude<keyof T, PK>
|
|
|
178
194
|
*/
|
|
179
195
|
export type ITSPickAndPartialOther<T, RK extends keyof T, PK extends Exclude<keyof T, RK> = Exclude<keyof T, RK>> = Pick<T, RK> & ITSPartialPick<T, PK>;
|
|
180
196
|
/**
|
|
181
|
-
*
|
|
182
|
-
* Keep specified keys as Required, other keys unchanged
|
|
197
|
+
* Makes the specified properties required while preserving all other properties.
|
|
183
198
|
*
|
|
184
|
-
*
|
|
185
|
-
* interface User { name: string; age: number; email: string; }
|
|
186
|
-
* type Result = ITSRequiredWith<User, 'name'>;
|
|
187
|
-
* // type Result = { name: string; age: number; email: string; }
|
|
199
|
+
* If `K` is `never`, `T` is returned unchanged.
|
|
188
200
|
*/
|
|
189
|
-
export type ITSRequiredWith<T, K extends keyof T> = Omit<T, K> & ITSRequiredPick<T, K>;
|
|
201
|
+
export type ITSRequiredWith<T, K extends keyof T> = ITSLogicIsNever<K> extends true ? T : Omit<T, K> & ITSRequiredPick<T, K>;
|
|
190
202
|
/**
|
|
191
|
-
*
|
|
192
|
-
* Keep specified keys as Partial, other keys unchanged
|
|
203
|
+
* Makes the specified properties optional while preserving all other properties.
|
|
193
204
|
*
|
|
194
|
-
*
|
|
195
|
-
* interface User { name: string; age: number; email: string; }
|
|
196
|
-
* type Result = ITSPartialWith<User, 'name'>;
|
|
197
|
-
* // type Result = { name?: string; age: number; email: string; }
|
|
205
|
+
* If `K` is `never`, `T` is returned unchanged.
|
|
198
206
|
*/
|
|
199
|
-
export type ITSPartialWith<T, K extends keyof T> = Omit<T, K> & ITSPartialPick<T, K>;
|
|
207
|
+
export type ITSPartialWith<T, K extends keyof T> = ITSLogicIsNever<K> extends true ? T : Omit<T, K> & ITSPartialPick<T, K>;
|
|
200
208
|
/**
|
|
201
209
|
* 確保物件至少具有指定的鍵集合中的一個
|
|
202
210
|
* Ensure the object has at least one of the specified key sets
|
package/lib/type/record.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record.js","sourceRoot":"","sources":["record.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * 記錄(Record)類型操作工具\n * Record Type Manipulation Utilities\n
|
|
1
|
+
{"version":3,"file":"record.js","sourceRoot":"","sources":["record.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG","sourcesContent":["/**\n * 記錄(Record)類型操作工具\n * Record Type Manipulation Utilities\n *\n * 提供物件類型選擇、覆寫、合併等操作\n * Provides object type selection, overwrite, merge and other operations\n *\n * Created by user on 2019/6/11.\n */\n\nimport type { ITSKeyofBothDiff, ITSKeyofBothSame, ITSKeyofDiff, ITSKeyofSame } from '../helper/filter';\nimport { ITSLogicIsNever } from '../logic/never';\n\nexport type { ITSRequireRecord, ITSPartialRecord } from '../type/record/partial';\n\n/**\n * 取得兩個鍵集合的差異(已棄用)\n * Get the difference between two key sets (deprecated)\n *\n * @deprecated 請使用 ITSKeyofDiff 取代 / Please use ITSKeyofDiff instead\n */\nexport type ITSDiff<T extends keyof any, U extends keyof any> = (\n\t{ [P in T]: P }\n\t&\n\t{ [P in U]: never }\n\t&\n\t{ [x: string]: never }\n\t)[T];\n\n/**\n * 選擇 T 中與 U 相同的鍵\n * Pick keys from T that are the same as U\n *\n * @example\n * type A = { a: 1; b: 2; };\n * type B = { a: 3; c: 4; };\n * type Result = ITSPickSame<A, B>;\n * // type Result = { a: 1 }\n */\nexport type ITSPickSame<T, U> = Pick<T, ITSKeyofSame<T, U>>;\n\n/**\n * 選擇 T 中與 U 不同的鍵\n * Pick keys from T that are different from U\n *\n * @example\n * type A = { a: 1; b: 2; };\n * type B = { a: 3; c: 4; };\n * type Result = ITSPickDiff<A, B>;\n * // type Result = { b: 2 }\n */\nexport type ITSPickDiff<T, U> = Pick<T, ITSKeyofDiff<T, U>>;\n\n/**\n * 選擇 T 與 U 中同時存在的鍵\n * Pick keys that exist in both T and U\n *\n * @example\n * type A = { a: 1; b: 2; };\n * type B = { a: 3; c: 4; };\n * type Result = ITSPickBothSame<A, B>;\n * // type Result = { a: 1 }\n */\nexport type ITSPickBothSame<T, U> = Pick<T & U, ITSKeyofBothSame<T, U>>;\n\n/**\n * 選擇 T 與 U 中不同時存在的鍵\n * Pick keys that do not exist in both T and U\n *\n * @example\n * type A = { a: 1; b: 2; };\n * type B = { a: 3; c: 4; };\n * type Result = ITSPickBothDiff<A, B>;\n * // type Result = { b: 2; c: 4 }\n */\nexport type ITSPickBothDiff<T, U> = Pick<T & U, ITSKeyofBothDiff<T, U>>;\n\n/**\n * 選擇指定鍵集合 K(必須是 T 與 U 中同時存在的鍵)\n * Pick a specified key set K (must be keys that exist in both T and U)\n */\nexport type ITSPickBoth<T, U, K extends ITSKeyofBothSame<T, U> = ITSKeyofBothSame<T, U>> = Pick<T & U, K>;\n\n/**\n * 取得物件成員的類型\n * Get the type of an object member\n *\n * @see https://stackoverflow.com/questions/49198713/override-the-properties-of-an-interface-in-typescript\n */\nexport type ITSPickMember<T, K extends keyof T> = T[K];\n\n/**\n * 排除指定鍵(已棄用)\n * Exclude specified keys (deprecated)\n *\n * @deprecated 請使用 Omit 取代 / Please use Omit instead\n */\nexport type ITSPickNot<T, K extends keyof T> = Omit<T, K>;\n\n/**\n * 覆寫物件類型的屬性\n * Overwrite properties of an object type\n *\n * 用 U 中的屬性覆寫 T 中的同名屬性\n * Overwrites properties in T with the same name from U\n *\n * @see https://stackoverflow.com/questions/49198713/override-the-properties-of-an-interface-in-typescript\n *\n * @example\n * interface A1 { s: string }\n * type A2 = ITSOverwrite<A1, { s: number }>;\n * // type A2 = { s: number }\n */\nexport type ITSOverwrite<T, U> = Omit<T, keyof U> & U;\n\n/**\n * 合併兩個物件類型,處理衝突屬性\n * Merge two object types, handling conflicting properties\n *\n * 對於 T 與 U 中同時存在的鍵,取兩者的聯集類型\n * For keys that exist in both T and U, takes the union type of both\n *\n * @example\n * type Test1 = { id: number, code: string }\n * type Test2 = { id: string, code: number }\n * type Test3 = ITSMergeBoth<Test1, Test2>\n * // type Test3 = { id: string | number; code: string | number }\n * @see https://github.com/microsoft/TypeScript/issues/35627\n */\nexport type ITSMergeBoth<T, U> = ITSPickBothDiff<T, U> & Pick<T | U, ITSKeyofBothSame<T, U>>;\n\n/**\n * Makes the selected properties of a type required.\n *\n * This is the standard version and is intended for a single object type.\n *\n * @example\n * type User = {\n * name?: string;\n * age?: number;\n * };\n *\n * type Result = ITSRequiredPick<User, \"name\">;\n * // {\n * // name: string;\n * // age?: number;\n * // }\n */\nexport type ITSRequiredPick<T, K extends keyof T = keyof T> = {\n\t[P in K]-?: T[P];\n};\n\n/**\n * Makes the selected properties of a type optional.\n *\n * This is the standard version and is intended for a single object type.\n *\n * @example\n * type User = {\n * name: string;\n * age: number;\n * };\n *\n * type Result = ITSPartialPick<User, \"name\">;\n * // {\n * // name?: string;\n * // }\n */\nexport type ITSPartialPick<T, K extends keyof T = keyof T> = {\n\t[P in K]?: T[P];\n};\n\n/**\n * 複製類型並將指定鍵RK設為必填,其他鍵Pk設為可選\n * Clone a type and mark specified keys as Required, other keys as Partial\n *\n * @example\n * interface User { name: string; age: number; email: string; }\n * type Result = ITSPickExtra<User, 'name', 'email'>;\n * // type Result = { name: string; } & { age?: number; email?: string; }\n */\nexport type ITSPickExtra<T, RK extends keyof T, PK extends Exclude<keyof T, RK> = Exclude<keyof T, RK>> =\n\tITSRequiredPick<T, RK>\n\t& ITSPartialPick<T, PK>;\n\n/**\n * 複製類型並將指定鍵Pk設為可選,其他鍵Rk設為必填(與 ITSPickExtra 相反)\n * Clone a type and mark specified keys as Partial, other keys as Required (opposite of ITSPickExtra)\n *\n * @example\n * interface User { name: string; age: number; email: string; }\n * type Result = ITSPickExtra2<User, 'name', 'email'>;\n * // type Result = { name?: string; } & { age: number; email: string; }\n */\nexport type ITSPickExtra2<T, PK extends keyof T, RK extends Exclude<keyof T, PK> = Exclude<keyof T, PK>> =\n\tITSRequiredPick<T, RK>\n\t& ITSPartialPick<T, PK>;\n\n/**\n * 保留指定鍵不變(維持原本的必選/可選/唯讀屬性),其他鍵變為可選\n * Keep specified keys unchanged (preserving required/optional/readonly modifiers), other keys become Partial\n *\n * 與 ITSPickExtra 的差異:ITSPickExtra 會將指定鍵強制設為必填,而此類型保留原始修飾符\n * Difference from ITSPickExtra: ITSPickExtra forces specified keys to Required, while this type preserves original modifiers\n *\n * @see {@link ITSPickExtra} - 將指定鍵設為必填,其他鍵可選\n * @see {@link ITSPartialWith} - 將指定鍵設為可選,其他鍵不變\n *\n * @example\n * interface User { name: string; readonly id: string; age?: number; email: string; }\n * type Result = ITSPickAndPartialOther<User, 'name' | 'id'>;\n * // 輸出結果 / Output:\n * // { name: string; readonly id: string; } & { age?: number; email?: string; }\n * // 注意:name 維持必選,id 維持唯讀且必選,age 和 email 變為可選\n */\nexport type ITSPickAndPartialOther<T, RK extends keyof T, PK extends Exclude<keyof T, RK> = Exclude<keyof T, RK>> =\n\tPick<T, RK>\n\t& ITSPartialPick<T, PK>;\n\n/**\n * Makes the specified properties required while preserving all other properties.\n *\n * If `K` is `never`, `T` is returned unchanged.\n */\nexport type ITSRequiredWith<T, K extends keyof T> = ITSLogicIsNever<K> extends true\n\t? T\n\t: Omit<T, K> & ITSRequiredPick<T, K>;\n\n/**\n * Makes the specified properties optional while preserving all other properties.\n *\n * If `K` is `never`, `T` is returned unchanged.\n */\nexport type ITSPartialWith<T, K extends keyof T> = ITSLogicIsNever<K> extends true\n\t? T\n\t: Omit<T, K> & ITSPartialPick<T, K>;\n\n/**\n * 確保物件至少具有指定的鍵集合中的一個\n * Ensure the object has at least one of the specified key sets\n *\n * @see https://stackoverflow.com/questions/40510611/typescript-interface-require-one-of-two-properties-to-exist\n *\n * @example\n * interface User { name?: string; age?: number; }\n * type AtLeastOne = ITSRequireAtLeastOne<User, 'name' | 'age'>;\n * // 需要至少提供 name 或 age 其中一個\n */\nexport type ITSRequireAtLeastOne<T, Keys extends keyof T = keyof T> =\n\tOmit<T, Keys>\n\t& {\n\t[K in Keys]-?: ITSRequiredPick<T, K>\n\t& ITSPartialPick<T, Exclude<Keys, K>>\n}[Keys];\n\n/**\n * 確保物件只能具有指定的鍵集合中的其中一個(互斥)\n * Ensure the object can only have exactly one of the specified key sets (mutually exclusive)\n *\n * @see https://stackoverflow.com/questions/40510611/typescript-interface-require-one-of-two-properties-to-exist\n * @see {@link ITSPickOne} 另一種實現方式,使用 `void` 作為其餘鍵的類型\n *\n * @example\n * interface User { name?: string; age?: number; }\n * type OnlyOne1 = ITSRequireOnlyOne<User, 'name' | 'age'>;\n * // 輸出結果:\n * // type OnlyOne1 = { name: string; age?: never; } | { age: number; name?: never; }\n * // 只能提供 name 或 age 其中一個,不能同時提供\n */\nexport type ITSRequireOnlyOne<T, Keys extends keyof T = keyof T> =\n\tOmit<T, Keys>\n\t& {\n\t[K in Keys]-?: ITSRequiredPick<T, K>\n\t& Partial<Record<Exclude<Keys, K>, never>>\n}[Keys];\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"empty.js","sourceRoot":"","sources":["empty.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 空元組類型\n * Empty Tuple Type\n
|
|
1
|
+
{"version":3,"file":"empty.js","sourceRoot":"","sources":["empty.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG","sourcesContent":["/**\n * 空元組類型\n * Empty Tuple Type\n *\n * 提供空元組相關的類型定義\n * Provides empty tuple-related type definitions\n */\n\nimport { ITSArrayListMaybeReadonly } from '../base';\n\n/**\n * 空元組類型\n * Empty tuple type\n *\n * @example\n * type Empty = ITSEmptyTuple;\n * // type Empty = [] | readonly []\n */\nexport type ITSEmptyTuple = ITSArrayListMaybeReadonly<never>;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-type",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.14",
|
|
4
4
|
"description": "TypeScript 類型工具庫:提供豐富的類型操作工具和重新導出的內建類型 / TypeScript type utility library: provides rich type manipulation utilities and re-exported built-in types",
|
|
5
5
|
"keywords": [
|
|
6
6
|
".d.ts",
|
|
@@ -56,18 +56,18 @@
|
|
|
56
56
|
"test": "test"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
|
-
"coverage": "
|
|
60
|
-
"pretest": "
|
|
61
|
-
"test": "
|
|
59
|
+
"coverage": "pnpm run test --coverage",
|
|
60
|
+
"pretest": "pnpm run build",
|
|
61
|
+
"test": "pnpm run ts:check && pnpm run test:tsd",
|
|
62
62
|
"test:jest": "jest --passWithNoTests",
|
|
63
63
|
"test:jest:coverage": "node --run test:jest -- --coverage",
|
|
64
|
-
"test:jest:snapshot": "
|
|
65
|
-
"test:snapshot": "
|
|
64
|
+
"test:jest:snapshot": "pnpm run test:jest -u",
|
|
65
|
+
"test:snapshot": "pnpm run test -u",
|
|
66
66
|
"test:tsd": "tsd",
|
|
67
|
-
"build": "
|
|
68
|
-
"build-lib-toc": "
|
|
67
|
+
"build": "pnpm run build-lib-toc && tsc",
|
|
68
|
+
"build-lib-toc": "tsx ./test/script/toc && pnpm run build:toc",
|
|
69
69
|
"build:toc": "tsc --skipLibCheck & echo build:toc",
|
|
70
|
-
"preversion": "
|
|
70
|
+
"preversion": "pnpm run test && pnpm run postpublish:git:commit",
|
|
71
71
|
"prepublishOnly": "echo prepublishOnly",
|
|
72
72
|
"postpublish:git:commit": "git commit -m \"build(release): publish\" ./lib/index.d.ts ./lib & echo postpublish:git:commit",
|
|
73
73
|
"ncu": "yarn-tool ncu -u",
|
|
@@ -94,8 +94,11 @@
|
|
|
94
94
|
"tslib": ">=2.8.1",
|
|
95
95
|
"typedarray-dts": "^1.0.0"
|
|
96
96
|
},
|
|
97
|
+
"devDependencies": {
|
|
98
|
+
"@ts-type/object-freeze": "^1.0.14"
|
|
99
|
+
},
|
|
97
100
|
"peerDependencies": {
|
|
98
101
|
"ts-toolbelt": "^9.6.0"
|
|
99
102
|
},
|
|
100
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "673857cff12964d50e2da0224bd21fcf06c7744b"
|
|
101
104
|
}
|