@guillaume-docquier/tools-ts 1.2.0 → 1.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.
@@ -139,3 +139,25 @@ export type PartialProperties<TObject, TKey extends keyof TObject> = Omit<TObjec
139
139
  * ```
140
140
  */
141
141
  export type ValueOf<T> = T[keyof T];
142
+ /**
143
+ * Creates an enum type out of a const object.
144
+ * Useful for projects that run native Typescript in node and can't use enums, but want the same ergonomics.
145
+ * This is basically an alias of {@link ValueOf}.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * type MyEnum = Enumify<MyEnum>
150
+ * ^? "a" | "b" | "c"
151
+ * const MyEnum = {
152
+ * A: "a",
153
+ * B: "b",
154
+ * C: "c",
155
+ * } as const
156
+ *
157
+ * function useEnum(value: MyEnum) {}
158
+ *
159
+ * useEnum(MyEnum.A) // works
160
+ * useEnum("a") // also works
161
+ * ```
162
+ */
163
+ export type Enumify<TObject extends Record<string, string>> = ValueOf<TObject>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guillaume-docquier/tools-ts",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "My personal collection of typescript tools",
5
5
  "homepage": "https://github.com/Guillaume-Docquier/tools-ts",
6
6
  "repository": {