@@ -13,6 +13,30 @@ type Unbrand<T extends Primitive & Record<any, any>> = T extends string & Record
1313 ? Extract < undefined , Omit < T , any > >
1414 : T ;
1515
16+ /**
17+ * @title Type for Recursively Removing Branding Types.
18+ *
19+ * The `DeepStrictUnbrand<T>` type recursively processes the type `T` to remove any branding
20+ * that may have been added to primitive types or object properties. Branding often occurs when
21+ * extending or augmenting primitive types for type safety, and this type "unbrands" them, restoring
22+ * the original primitive type (e.g., `string`, `number`, `boolean`, etc.).
23+ *
24+ * The helper type `Unbrand<T>` is used to handle primitive types and their respective branding,
25+ * by stripping off any additional properties that may have been added to them.
26+ *
27+ * The recursion goes through:
28+ * - Arrays: It recursively processes elements of the array, maintaining deep unbranding.
29+ * - Objects: It recursively processes each key in the object, unbranding any branded properties.
30+ * - Primitives: It removes branding from primitive types (`string`, `number`, `boolean`, `symbol`, `null`, `undefined`).
31+ * - Dates: The `Date` type is preserved as it is.
32+ *
33+ * Example Usage:
34+ * ```ts
35+ * type Example1 = DeepStrictUnbrand<{ a: string & { __brand: 'unique' } }>; // { a: string }
36+ * type Example2 = DeepStrictUnbrand<{ a: { b: number & { __brand: 'id' } } }>; // { a: { b: number } }
37+ * type Example3 = DeepStrictUnbrand<Array<string & { __brand: 'email' }>>; // Array<string>
38+ * ```
39+ */
1640export type DeepStrictUnbrand < T > =
1741 T extends Array < Date >
1842 ? Array < Date >
0 commit comments