@cloudcome/utils-core 1.10.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/types.d.ts +13 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
package/dist/index.mjs
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -139,4 +139,17 @@ export type IsOnlyProperty<T, P> = keyof T extends P ? true : false;
|
|
|
139
139
|
* ```
|
|
140
140
|
*/
|
|
141
141
|
export type HasProperty<T, K> = K extends keyof T ? true : false;
|
|
142
|
+
/**
|
|
143
|
+
* 精确匹配类型
|
|
144
|
+
* @description 检查类型 T 是否精确匹配给定的形状 Shape。如果 T 包含 Shape 中不存在的额外属性,则不匹配。
|
|
145
|
+
* @template T - 要检查的类型
|
|
146
|
+
* @template Shape - 期望的形状/结构
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* type Result1 = Exact<{ a: 1 }, { a: 1 }>; // { a: 1 }
|
|
150
|
+
* type Result2 = Exact<{ a: 1; b: 2 }, { a: 1 }>; // never
|
|
151
|
+
* type Result3 = Exact<{ a: 1 }, { a: 1; b: 2 }>; // never
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
export type Exact<T, Shape> = T extends Shape ? (Exclude<keyof T, keyof Shape> extends never ? T : never) : never;
|
|
142
155
|
export {};
|