diff --git a/CHANGELOG.md b/CHANGELOG.md index 9983bda3..9db50b32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,82 @@ # Changelog +## v1.20.1 + +[compare changes](https://github.com/ashgw/ts-roids/compare/v1.17.0...v1.20.1) + +### 🚀 Enhancements + +- **#52:** Finish `ImmutableKeys` & `MutableKeys` ([17482f9](https://github.com/ashgw/ts-roids/commit/17482f9)) +- Set `IfExtends` ([a1625d0](https://github.com/ashgw/ts-roids/commit/a1625d0)) + +### 🏡 Chore + +- **release:** V1.18.0 ([68f1d2d](https://github.com/ashgw/ts-roids/commit/68f1d2d)) +- Cleanup source file ([fd40124](https://github.com/ashgw/ts-roids/commit/fd40124)) +- Cleanup ([e384ba9](https://github.com/ashgw/ts-roids/commit/e384ba9)) + +### ❤️ Contributors + +- AshGw ([@AshGw](http://github.com/AshGw)) + +## v1.20.0 + +[compare changes](https://github.com/ashgw/ts-roids/compare/v1.17.0...v1.20.0) + +### 🚀 Enhancements + +- **#52:** Finish `ImmutableKeys` & `MutableKeys` ([17482f9](https://github.com/ashgw/ts-roids/commit/17482f9)) +- Set `IfExtends` ([a1625d0](https://github.com/ashgw/ts-roids/commit/a1625d0)) + +### 🏡 Chore + +- **release:** V1.18.0 ([68f1d2d](https://github.com/ashgw/ts-roids/commit/68f1d2d)) +- Cleanup source file ([fd40124](https://github.com/ashgw/ts-roids/commit/fd40124)) +- Cleanup ([e384ba9](https://github.com/ashgw/ts-roids/commit/e384ba9)) + +### ❤️ Contributors + +- AshGw ([@AshGw](http://github.com/AshGw)) + +## v1.19.1 + +[compare changes](https://github.com/ashgw/ts-roids/compare/v1.17.0...v1.19.1) + +### 🚀 Enhancements + +- **#52:** Finish `ImmutableKeys` & `MutableKeys` ([17482f9](https://github.com/ashgw/ts-roids/commit/17482f9)) +- Set `IfExtends` ([a1625d0](https://github.com/ashgw/ts-roids/commit/a1625d0)) + +### 🏡 Chore + +- **release:** V1.18.0 ([68f1d2d](https://github.com/ashgw/ts-roids/commit/68f1d2d)) +- Cleanup source file ([fd40124](https://github.com/ashgw/ts-roids/commit/fd40124)) +- Cleanup ([e384ba9](https://github.com/ashgw/ts-roids/commit/e384ba9)) + +### ❤️ Contributors + +- AshGw ([@AshGw](http://github.com/AshGw)) + +## v1.19.0 + +[compare changes](https://github.com/ashgw/ts-roids/compare/v1.17.0...v1.19.0) + +### 🚀 Enhancements + +- **#52:** Finish `ImmutableKeys` & `MutableKeys` ([17482f9](https://github.com/ashgw/ts-roids/commit/17482f9)) +- Set `IfExtends` ([a1625d0](https://github.com/ashgw/ts-roids/commit/a1625d0)) + +### 🏡 Chore + +- **release:** V1.18.0 ([68f1d2d](https://github.com/ashgw/ts-roids/commit/68f1d2d)) +- Cleanup source file ([fd40124](https://github.com/ashgw/ts-roids/commit/fd40124)) +- Cleanup ([e384ba9](https://github.com/ashgw/ts-roids/commit/e384ba9)) + +### ❤️ Contributors + +- AshGw ([@AshGw](http://github.com/AshGw)) + ## v1.18.0 [compare changes](https://github.com/ashgw/ts-roids/compare/v1.16.0...v1.18.0) diff --git a/package.json b/package.json index 36f6e029..f74886f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ts-roids", - "version": "1.18.0", + "version": "1.20.1", "private": false, "description": "Extending the TS library with types and decorators that should've been built-in", "keywords": [ diff --git a/src/index.ts b/src/index.ts index dab321ca..99c2e37a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -275,27 +275,31 @@ export type NewType = { [__s]: true; } & N; -export type obj = { - person: { - name: string; - age: { - value: number; - }; - }; -}; - -export type DeepOmit = Str extends `${string}.${infer R}` +/** + * Type that recursively omits specified nested properties from an object type. + * @template T The input object type. + * @template P A string literal representing the path of properties to omit (e.g., 'person.name.value'). + * @example + * ```typescript + * type T = + * a: { + * b: string; + * b2: { + * c: { + * d: number; + * }; + * }; + * }; + * } + * + * DeepOmit // Results in: { a: { b: string; b2: {} } } + * ``` + */ +export type DeepOmit = P extends `${infer K}.${infer R}` ? { - [K in Keys]: DeepOmit; + [KT in Keys]: KT extends K ? DeepOmit : T[KT]; } - : T extends unknown - ? Omit - : T; - -export type test1 = DeepOmit; // {} -export type test2 = DeepOmit; // { person: { age: { value: number } } } -export type test3 = DeepOmit; // { person: { name: string; age: { value: number } } } -export type test4 = DeepOmit; // { person: { name: string; age: {} } } + : Omit; export type EmptyArray = []; /** @@ -327,9 +331,9 @@ export type ArrayTranspose< }; }; -export type Matrix = ArrayTranspose<[[1]]>; //[[1]] -export type Matrix1 = ArrayTranspose<[[1, 'i'], [3, 4]]>; // [[1, 3], ["i", 4]] -export type Matrix2 = ArrayTranspose<[[1, true, 3], [4, 5, 6]]>; // [[1, 4], [true, 5], [3, 6]] +export type Matrix2 = ArrayTranspose< + [[1, Optional, Nullable, 3], [4, 5, 6]] +>; // [[1, 4], [true, 5], [3, 6]] export type AlterKeyTypeWith, R> = Pick< T, @@ -359,9 +363,9 @@ export type OmitBy = Omit>; /** * Represents a export type that filters elements from an array based on a given predicate export type. - * @typeParam T The array export type to filter. - * @typeParam P The predicate export type used for filtering elements from `T`. - * @returns a new array export type containing only the elements of `T` that match `P`. + * @typeParam T The array to filter. + * @typeParam P The predicate used for filtering elements from `T`. + * @returns a new array type containing only the elements of `T` that match `P`. * @example * ```typescript * export type Numbers = [0, 1, 2, 3]; @@ -377,7 +381,8 @@ export type ArrayFilter = T extends [ : ArrayFilter : []; -export type EmptyObject = Exclude; +export type EmptyObject = NonNullable; +export type EmptyObject3 = Exclude; export type EmptyObject2 = Record; export type OptionalKeys = { [K in Keys]-?: EmptyObject extends Pick ? K : never; diff --git a/tests/array-transpose.test.ts b/tests/array-transpose.test.ts new file mode 100644 index 00000000..3a3ed653 --- /dev/null +++ b/tests/array-transpose.test.ts @@ -0,0 +1,34 @@ +import { Optional, Nullable, Numeric, TestType, ArrayTranspose } from 'src'; +import { test, expect } from 'vitest'; + +test('_', () => { + const result: TestType< + ArrayTranspose<[[1, Optional, Nullable, 3], [4, 5, 6]]>, + [[1, 4], [Optional, 5], [Nullable, 6], [3, never]], + true + > = true; + expect(result).toBe(true); +}); + +test('_', () => { + const result: TestType, [[1]], true> = true; + expect(result).toBe(true); +}); + +test('_', () => { + const result: TestType< + ArrayTranspose<[[1, true, 3], [4, 5, 6]]>, + [[1, 4], [true, 5], [3, 6]], + true + > = true; + expect(result).toBe(true); +}); + +test('_', () => { + const result: TestType< + ArrayTranspose<[[1, 'i'], [3, 4]]>, + [[1, 3], ['i', 4]], + true + > = true; + expect(result).toBe(true); +}); diff --git a/tests/deep-omit.test.ts b/tests/deep-omit.test.ts new file mode 100644 index 00000000..6eafedf8 --- /dev/null +++ b/tests/deep-omit.test.ts @@ -0,0 +1,41 @@ +import { DeepOmit, TestType, EmptyObject } from 'src'; +import { test, expect } from 'vitest'; + +type Actual = { + a: { + b: string; + b2: { + c: { + d: number; + }; + }; + }; +}; + +test('_', () => { + const result: TestType< + DeepOmit, + { a: { b: string; b2: EmptyObject } }, + true + > = true; + expect(result).toBe(true); +}); + +test('_', () => { + const result: TestType< + DeepOmit, + { a: { b: string; b2: EmptyObject } }, + true + > = true; + expect(result).toBe(true); +}); + +test('_', () => { + const result: TestType, EmptyObject, true> = true; + expect(result).toBe(true); +}); + +test('_', () => { + const result: TestType, Actual, true> = true; + expect(result).toBe(true); +});