diff --git a/README.md b/README.md index 8785d10..4d79d63 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ npm i @utype/core OmitByType OmitByTypeFuzzy OmitByTypeExact +Subtract Intersection PickByRequired diff --git a/docs/.vitepress/pages/types.json b/docs/.vitepress/pages/types.json index 8c35f4e..bc8f75f 100644 --- a/docs/.vitepress/pages/types.json +++ b/docs/.vitepress/pages/types.json @@ -146,6 +146,10 @@ "link": "/omit-by-type-exact", "text": "OmitByTypeExact" }, + { + "link": "/subtract", + "text": "Subtract" + }, { "link": "/intersection", "text": "Intersection" 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 984aa08..5357db4 100644 --- a/packages/core/index.d.ts +++ b/packages/core/index.d.ts @@ -35,6 +35,7 @@ export * from './PickByTypeExact' export * from './OmitByType' export * from './OmitByTypeFuzzy' export * from './OmitByTypeExact' +export * from './Subtract' export * from './Intersection' export * from './PickByRequired'