From b04aaa945867b83a675eb50101de6d5d18c50bdd Mon Sep 17 00:00:00 2001
From: wzc520pyfm <1528857653@qq.com>
Date: Mon, 15 Jan 2024 21:14:02 +0800
Subject: [PATCH] feat(core): add Subtract type
---
README.md | 1 +
docs/.vitepress/pages/types.json | 4 ++++
docs/types/subtract.md | 21 +++++++++++++++++++++
packages/core/Subtract/index.d.test.ts | 18 ++++++++++++++++++
packages/core/Subtract/index.d.ts | 12 ++++++++++++
packages/core/index.d.ts | 1 +
6 files changed, 57 insertions(+)
create mode 100644 docs/types/subtract.md
create mode 100644 packages/core/Subtract/index.d.test.ts
create mode 100644 packages/core/Subtract/index.d.ts
diff --git a/README.md b/README.md
index bb99bb8..ab204d6 100644
--- a/README.md
+++ b/README.md
@@ -64,6 +64,7 @@ npm i @utype/core
+
### 🚀 String Operation
diff --git a/docs/.vitepress/pages/types.json b/docs/.vitepress/pages/types.json
index 9896d9e..7881e6e 100644
--- a/docs/.vitepress/pages/types.json
+++ b/docs/.vitepress/pages/types.json
@@ -138,6 +138,10 @@
"link": "/omit-by-type-exact",
"text": "OmitByTypeExact"
},
+ {
+ "link": "/subtract",
+ "text": "Subtract"
+ },
{
"link": "/kebab-case",
"text": "KebabCase"
diff --git a/docs/types/subtract.md b/docs/types/subtract.md
new file mode 100644
index 0000000..e8261df
--- /dev/null
+++ b/docs/types/subtract.md
@@ -0,0 +1,21 @@
+---
+category: Generate Object
+---
+
+# Subtract
+
+
+
+From T remove properties that exist in U.
+
+## Usage
+
+```ts
+import type { Subtract } from '@utype/core'
+
+type Prop = { name: string; age: number; visible: boolean }
+type DefaultProps = { age: number; sex: string }
+
+// Expect: { name: string; visible: boolean } // [!code highlight]
+type SubtractProp = Subtract
+```
\ No newline at end of file
diff --git a/packages/core/Subtract/index.d.test.ts b/packages/core/Subtract/index.d.test.ts
new file mode 100644
index 0000000..37bf91a
--- /dev/null
+++ b/packages/core/Subtract/index.d.test.ts
@@ -0,0 +1,18 @@
+import type { Subtract } from "@utype/core";
+import { Equal, Expect } from "@utype/shared";
+
+type Case = {
+ name: string;
+ age: number;
+ visible: boolean;
+};
+type DefaultCase = {
+ age: number;
+ sex: string;
+};
+type SubtractCase = {
+ name: string;
+ visible: boolean;
+};
+
+type cases = [Expect, SubtractCase>>];
diff --git a/packages/core/Subtract/index.d.ts b/packages/core/Subtract/index.d.ts
new file mode 100644
index 0000000..dca3b67
--- /dev/null
+++ b/packages/core/Subtract/index.d.ts
@@ -0,0 +1,12 @@
+import { Keys } from "@utype/shared";
+
+/**
+ * Subtract
+ * @description From T remove properties that exist in U.
+ * @example
+ * type Prop = { name: string; age: number; visible: boolean }
+ * type DefaultProps = { age: number; sex: string }
+ * // Expect: { name: string; visible: boolean }
+ * type SubtractProp = Subtract
+ */
+export type Subtract = Pick, Keys>>;
diff --git a/packages/core/index.d.ts b/packages/core/index.d.ts
index 019bada..62c5fac 100644
--- a/packages/core/index.d.ts
+++ b/packages/core/index.d.ts
@@ -33,6 +33,7 @@ export * from './PickByTypeExact'
export * from './OmitByType'
export * from './OmitByTypeFuzzy'
export * from './OmitByTypeExact'
+export * from './Subtract'
export * from './KebabCase'
export * from './SnakeCase'