ts-type 3.0.13 → 3.0.15
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 +35 -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 +139 -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
|
@@ -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,139 @@
|
|
|
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
|
+
};
|
|
136
|
+
export type ITSUnionToOptional<T> = [T] extends [infer U] ? {
|
|
137
|
+
[K in ITSKeyOfUnion<U>]?: U extends Record<K, any> ? U[K] : never;
|
|
138
|
+
} : never;
|
|
139
|
+
export type ITSAnyOfUnion<T> = ITSUnionToOptional<T> & T;
|
|
@@ -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\tT,\r\n\tK extends ITSKeyOfUnion<T>\r\n> = false extends (\r\n\t\tT extends unknown\r\n\t\t\t? K extends keyof T\r\n\t\t\t\t? {} extends Pick<T, K>\r\n\t\t\t\t\t? false\r\n\t\t\t\t\t: true\r\n\t\t\t\t: false\r\n\t\t\t: never\r\n\t\t)\r\n\t? false\r\n\t: 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\t[K in ITSKeyOfUnion<T>]:\r\n\tITSIsRequiredInUnion<T, K> extends true\r\n\t\t? K\r\n\t\t: 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\tExclude<\r\n\t\tITSKeyOfUnion<T>,\r\n\t\tITSKeyOfUnionRequired<T>\r\n\t>;\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\tT,\r\n\tK extends ITSKeyOfUnion<T>\r\n> = Omit<ITSUnionFlat<T>, K>\r\n\t& {\r\n\t[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\tT,\r\n\tK extends ITSKeyOfUnion<T>\r\n> = Omit<ITSUnionFlat<T>, K>\r\n\t& {\r\n\t[P in K]-?: ITSValueOfUnion<T, P>;\r\n};\r\n\r\n// ----------------\r\n\r\nexport type ITSUnionToOptional<T> = [T] extends [infer U]\r\n\t? { [K in ITSKeyOfUnion<U>]?: U extends Record<K, any> ? U[K] : never }\r\n\t: never;\r\n\r\nexport type ITSAnyOfUnion<T> = ITSUnionToOptional<T> & T;\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.15",
|
|
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.15"
|
|
99
|
+
},
|
|
97
100
|
"peerDependencies": {
|
|
98
101
|
"ts-toolbelt": "^9.6.0"
|
|
99
102
|
},
|
|
100
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "b1febe34d831268743202cf8176775b35ec0bd05"
|
|
101
104
|
}
|