@evolu/common 6.0.1-preview.17 → 6.0.1-preview.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/Types.ts CHANGED
@@ -78,82 +78,6 @@ export type NullablePartial<
78
78
  */
79
79
  export type IntentionalNever = never;
80
80
 
81
- /**
82
- * A utility interface for creating branded types.
83
- *
84
- * Branded types enhance type safety by differentiating otherwise identical base
85
- * types, such as `number` or `string`, to enforce stricter type checks.
86
- *
87
- * Supports multiple brands, allowing types to act like flags.
88
- *
89
- * ### Example 1: Single Brand
90
- *
91
- * ```ts
92
- * // A branded type definition
93
- * type UserId = number & Brand<"UserId">;
94
- *
95
- * // A function that creates `UserId` values.
96
- * // Casting with `as UserId` is unsafe, so `createUserId` must be unit-tested.
97
- * const createUserId = (): UserId => {
98
- * return 123 as UserId; // Unsafe casting
99
- * };
100
- *
101
- * const userId = createUserId();
102
- *
103
- * // A function that accepts only `UserId`.
104
- * const getUser = (id: UserId) => {
105
- * // Implementation
106
- * };
107
- *
108
- * getUser(userId); // ✅ Valid
109
- * getUser(123); // ❌ TypeScript error
110
- * getUser("123"); // ❌ TypeScript error
111
- * ```
112
- *
113
- * ### Example 2: Multiple Brands
114
- *
115
- * ```ts
116
- * // Define branded types
117
- * type Min1 = string & Brand<"Min1">;
118
- * type Max100 = string & Brand<"Max100">;
119
- * type Min1Max100 = string & Brand<"Min1" | "Max100">;
120
- *
121
- * // Functions requiring specific brands
122
- * const requiresMin1 = (value: Min1): void => {};
123
- * const requiresMax100 = (value: Max100): void => {};
124
- *
125
- * // Values with single brands
126
- * const min1Value: Min1 = "hello" as Min1;
127
- * const max100Value: Max100 = "world" as Max100;
128
- *
129
- * // Value with multiple brands
130
- * const min1Max100Value: Min1Max100 = "typescript" as Min1Max100;
131
- *
132
- * // Valid cases
133
- * requiresMin1(min1Value); // ✅ Valid
134
- * requiresMax100(max100Value); // ✅ Valid
135
- * requiresMin1(min1Max100Value); // ✅ Valid: Min1Max100 satisfies Min1
136
- * requiresMax100(min1Max100Value); // ✅ Valid: Min1Max100 satisfies Max100
137
- * ```
138
- */
139
- export interface Brand<B extends string> {
140
- readonly [__brand]: Readonly<Record<B, true>>;
141
- }
142
-
143
- declare const __brand: unique symbol;
144
-
145
- /**
146
- * Determines whether a type `T` is a branded type.
147
- *
148
- * Works with any base type intersected with a `Brand`.
149
- *
150
- * ### Examples
151
- *
152
- * - `IsBranded<string>` -> false
153
- * - `IsBranded<string & Brand<"X">>` -> true
154
- */
155
- export type IsBranded<T> = T extends Brand<string> ? true : false;
156
-
157
81
  /**
158
82
  * String | number | bigint | boolean | undefined | null
159
83
  *
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./Array.js";
2
2
  export * from "./Assert.js";
3
3
  export * from "./BigInt.js";
4
+ export * from "./Brand.js";
4
5
  export * from "./Buffer.js";
5
6
  export * from "./Callbacks.js";
6
7
  export * from "./Console.js";