-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: application of unbranding type to types not applied
- Loading branch information
Showing
3 changed files
with
19 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
import { DeepStrictUnbrand } from './DeepStrictUnbrand'; | ||
|
||
/** | ||
* A utility type that recursively converts all `Date` types within a nested object or array to `string`. | ||
* | ||
* - If `T` is an array of objects, the type processes each element recursively. | ||
* - If `T` is a `Date`, it is converted to `string`. | ||
* - If `T` is an object, each key is checked recursively for `Date` types or nested objects. | ||
*/ | ||
export type DeepDateToString<T> = | ||
T extends Array<infer I extends object> | ||
export type DeepDateToString<T extends object> = | ||
DeepStrictUnbrand<T> extends Array<infer I extends object> | ||
? Array<DeepDateToString<I>> | ||
: T extends Date | ||
? string | ||
: { | ||
[K in keyof T]: T[K] extends infer I | ||
? I extends Date | ||
? string | ||
: I extends object | ||
? DeepDateToString<I> | ||
: DeepStrictUnbrand<I> extends object | ||
? DeepDateToString<DeepStrictUnbrand<I>> | ||
: I | ||
: never; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters