@guillaume-docquier/tools-ts 6.2.0 → 6.3.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/README.md +11 -10
- package/dist/Brand.d.ts +30 -0
- package/dist/Brand.js +8 -0
- package/dist/Brand.js.map +1 -0
- package/dist/entry.tools-ts.d.ts +1 -0
- package/dist/entry.tools-ts.js +1 -0
- package/dist/entry.tools-ts.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,16 +68,17 @@ pseudo-random sequences.
|
|
|
68
68
|
|
|
69
69
|
These exports are type-only helpers for common TypeScript modeling problems.
|
|
70
70
|
|
|
71
|
-
| Export | What it is
|
|
72
|
-
| ------------------------------------------ |
|
|
73
|
-
| `
|
|
74
|
-
| `
|
|
75
|
-
| `
|
|
76
|
-
| `
|
|
77
|
-
| `
|
|
78
|
-
| `
|
|
79
|
-
| `
|
|
80
|
-
| `
|
|
71
|
+
| Export | What it is | Use it when |
|
|
72
|
+
| ------------------------------------------ | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
|
|
73
|
+
| `Branded`, `branded` | A nominal typing helper plus a runtime no-op for branding values. | Structurally identical values need distinct domain types, such as separate ID kinds. |
|
|
74
|
+
| `ConstructorType` | A type for class constructors. | A function accepts a class and later uses `new` or `instanceof` against it. |
|
|
75
|
+
| `EnumKeyType`, `EnumValueType`, `EnumType` | Broad shapes for enum-like objects. | You are writing generic utilities that operate on TypeScript enums or const-object enums. |
|
|
76
|
+
| `Enumify` | Converts a const object into a union of its values. | A project avoids TypeScript `enum` but wants enum-like ergonomics from `as const` objects. |
|
|
77
|
+
| `ValueOf` | Produces a union of an object's value types. | You need the values of a lookup object as a type. |
|
|
78
|
+
| `Prettify` | Re-expands an object type for easier editor hovers. | Intersections or mapped types are correct but hard to read in tooling. |
|
|
79
|
+
| `OmitOverUnion` | Applies `Omit` distributively across union members. | Native `Omit` collapses a discriminated union in a way that loses member-specific fields. |
|
|
80
|
+
| `PartialProperties` | Makes selected object properties partial, not the whole object. | Only nested property objects should become partial while the parent shape stays required. |
|
|
81
|
+
| `Mutable` | Removes `readonly` from selected properties. | You have a narrow, deliberate mutation need. Avoid this unless there is no cleaner model. |
|
|
81
82
|
|
|
82
83
|
### Logging
|
|
83
84
|
|
package/dist/Brand.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
declare const brand: unique symbol;
|
|
2
|
+
declare const baseType: unique symbol;
|
|
3
|
+
type AnyBrand = Branded<unknown, unknown>;
|
|
4
|
+
type TypeOf<TBrand extends AnyBrand> = TBrand[typeof baseType];
|
|
5
|
+
/**
|
|
6
|
+
* Type utility to create branded types.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* type UserId = Branded<string, "userId">
|
|
11
|
+
* function getUser(userId: UserId): User {}
|
|
12
|
+
*
|
|
13
|
+
* const str = "a string"
|
|
14
|
+
* const userId = branded<UserId>("user id")
|
|
15
|
+
*
|
|
16
|
+
* getUser(str) // S2345: Argument of type string is not assignable to parameter of type UserId
|
|
17
|
+
* getUser(userId) // works!
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export type Branded<TType, TBrand> = TType & {
|
|
21
|
+
[brand]: TBrand;
|
|
22
|
+
} & {
|
|
23
|
+
[baseType]: TType;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Brands a value.
|
|
27
|
+
* This is just type gymnastics to declare intent, the value is returned as-is at runtime.
|
|
28
|
+
*/
|
|
29
|
+
export declare function branded<TBrand extends AnyBrand>(value: TypeOf<TBrand>): TBrand;
|
|
30
|
+
export {};
|
package/dist/Brand.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Brand.js","sourceRoot":"","sources":["../src/Brand.ts"],"names":[],"mappings":"AAuBA;;;GAGG;AACH,MAAM,UAAU,OAAO,CAA0B,KAAqB;IACpE,OAAO,KAAe,CAAA;AACxB,CAAC"}
|
package/dist/entry.tools-ts.d.ts
CHANGED
package/dist/entry.tools-ts.js
CHANGED
|
@@ -25,4 +25,5 @@ export { mulberry32Prng } from "./rng/mulberry32prng.js";
|
|
|
25
25
|
export { Datetime } from "./Datetime.js";
|
|
26
26
|
export { Time, UnitOfTime } from "./measurements/Time.js";
|
|
27
27
|
export { Timer } from "./Timer.js";
|
|
28
|
+
export { branded } from "./Brand.js";
|
|
28
29
|
//# sourceMappingURL=entry.tools-ts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry.tools-ts.js","sourceRoot":"","sources":["../src/entry.tools-ts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAI5C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,MAAM,EAA8B,MAAM,aAAa,CAAA;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAE3C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;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