@infra-blocks/types 0.21.0 → 0.22.0-alpha.0

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.
@@ -1,3 +1,28 @@
1
+ /**
2
+ * The unique symbol used for branding types.
3
+ */
4
+ export declare const brand: unique symbol;
5
+ /**
6
+ * Declares the branding of a type.
7
+ *
8
+ * Branding a type circumvent TypeScript's structural typing by adding an unique property to a type,
9
+ * making it incompatible with other types even if they share the same structure.
10
+ *
11
+ * Use it as such:
12
+ * ```typescript
13
+ * type UserId = string & Brand<"UserId">;
14
+ *
15
+ * // The proper way to obtain a UserId.
16
+ * function parseUserId(id: string): UserId {
17
+ * ...
18
+ * }
19
+ * ```
20
+ */
21
+ export type Brand<T extends string | number | symbol = string | number | symbol> = {
22
+ [brand]: {
23
+ [k in T]: true;
24
+ };
25
+ };
1
26
  /**
2
27
  * Convenience type to represent environment variables.
3
28
  */
package/lib/cjs/types.js CHANGED
@@ -1,3 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.brand = void 0;
4
+ /**
5
+ * The unique symbol used for branding types.
6
+ */
7
+ exports.brand = Symbol("__brand");
3
8
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,KAAK,GAAkB,MAAM,CAAC,SAAS,CAAC,CAAC"}
@@ -1,3 +1,28 @@
1
+ /**
2
+ * The unique symbol used for branding types.
3
+ */
4
+ export declare const brand: unique symbol;
5
+ /**
6
+ * Declares the branding of a type.
7
+ *
8
+ * Branding a type circumvent TypeScript's structural typing by adding an unique property to a type,
9
+ * making it incompatible with other types even if they share the same structure.
10
+ *
11
+ * Use it as such:
12
+ * ```typescript
13
+ * type UserId = string & Brand<"UserId">;
14
+ *
15
+ * // The proper way to obtain a UserId.
16
+ * function parseUserId(id: string): UserId {
17
+ * ...
18
+ * }
19
+ * ```
20
+ */
21
+ export type Brand<T extends string | number | symbol = string | number | symbol> = {
22
+ [brand]: {
23
+ [k in T]: true;
24
+ };
25
+ };
1
26
  /**
2
27
  * Convenience type to represent environment variables.
3
28
  */
package/lib/esm/types.js CHANGED
@@ -1,2 +1,5 @@
1
- export {};
1
+ /**
2
+ * The unique symbol used for branding types.
3
+ */
4
+ export const brand = Symbol("__brand");
2
5
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAkB,MAAM,CAAC,SAAS,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@infra-blocks/types",
3
- "version": "0.21.0",
3
+ "version": "0.22.0-alpha.0",
4
4
  "description": "Typescript types utility package.",
5
5
  "keywords": [
6
6
  "type",