@ashetm/types 1.3.1 → 1.3.2

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/README.md CHANGED
@@ -222,6 +222,8 @@ type D = SnakeCase<'user-name id'>; // 'user_name_id'
222
222
 
223
223
  `Brand<T, Name>` tags `T` with a name, so two types with the same shape can't be mixed up. A branded value is still a `T`; a plain `T` must be cast to get the brand.
224
224
 
225
+ The brand is a type-only `__brand` key (nothing at runtime), so the same `Brand` from an ESM and a CommonJS project match. A `Brand` from 1.3.0 or 1.3.1 does not match one from 1.3.2+ if both versions are installed.
226
+
225
227
  ```ts
226
228
  type UserId = Brand<string, 'UserId'>;
227
229
  type OrderId = Brand<string, 'OrderId'>;
package/dist/brand.d.cts CHANGED
@@ -1,8 +1,10 @@
1
- declare const brand: unique symbol;
2
1
  /**
3
2
  * `T` tagged with a `Name`, so two types with the same shape can't be mixed up.
4
3
  * A branded value is still a `T`; a plain `T` must be cast to get the brand.
5
4
  *
5
+ * The brand is a type-only `__brand` key: it does not exist at runtime. A string key (not a `unique symbol`)
6
+ * keeps the ESM and CommonJS copies of this type the same.
7
+ *
6
8
  * @example
7
9
  * ```ts
8
10
  * type UserId = Brand<string, 'UserId'>;
@@ -15,6 +17,5 @@ declare const brand: unique symbol;
15
17
  * ```
16
18
  */
17
19
  export type Brand<T, Name extends string> = T & {
18
- readonly [brand]: Name;
20
+ readonly __brand: Name;
19
21
  };
20
- export {};
package/dist/brand.d.ts CHANGED
@@ -1,8 +1,10 @@
1
- declare const brand: unique symbol;
2
1
  /**
3
2
  * `T` tagged with a `Name`, so two types with the same shape can't be mixed up.
4
3
  * A branded value is still a `T`; a plain `T` must be cast to get the brand.
5
4
  *
5
+ * The brand is a type-only `__brand` key: it does not exist at runtime. A string key (not a `unique symbol`)
6
+ * keeps the ESM and CommonJS copies of this type the same.
7
+ *
6
8
  * @example
7
9
  * ```ts
8
10
  * type UserId = Brand<string, 'UserId'>;
@@ -15,6 +17,5 @@ declare const brand: unique symbol;
15
17
  * ```
16
18
  */
17
19
  export type Brand<T, Name extends string> = T & {
18
- readonly [brand]: Name;
20
+ readonly __brand: Name;
19
21
  };
20
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ashetm/types",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Small, dependency-free TypeScript utility types (Nullable, NonEmptyArray, DeepPartial, Brand, Prettify, LiteralUnion, Merge, JsonValue, Paths, CamelCase, Tuple, ...). Types only: adds nothing to your bundle.",
5
5
  "contributors": [
6
6
  {