@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.
- package/lib/cjs/types.d.ts +25 -0
- package/lib/cjs/types.js +5 -0
- package/lib/cjs/types.js.map +1 -1
- package/lib/esm/types.d.ts +25 -0
- package/lib/esm/types.js +4 -1
- package/lib/esm/types.js.map +1 -1
- package/package.json +1 -1
package/lib/cjs/types.d.ts
CHANGED
|
@@ -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
package/lib/cjs/types.js.map
CHANGED
|
@@ -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"}
|
package/lib/esm/types.d.ts
CHANGED
|
@@ -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
package/lib/esm/types.js.map
CHANGED
|
@@ -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"}
|