We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
keysTyped
entriesTyped
1 parent 13ae3d4 commit 0417531Copy full SHA for 0417531
1 file changed
src/util.ts
@@ -1287,3 +1287,17 @@ export async function asyncSome<T>(
1287
export function isDefined<T>(value: T | null | undefined): value is T {
1288
return value !== undefined && value !== null;
1289
}
1290
+
1291
+/** Like `Object.keys`, but infers the correct key type. */
1292
+export function keysTyped<T extends Record<string, any>>(
1293
+ object: T,
1294
+): Array<keyof T> {
1295
+ return Object.keys(object) as Array<keyof T>;
1296
+}
1297
1298
+/** Like `Object.entries`, but infers the correct key type. */
1299
+export function entriesTyped<T extends Record<string, any>>(
1300
1301
+): Array<[keyof T, NonNullable<T[keyof T]>]> {
1302
+ return Object.entries(object) as Array<[keyof T, NonNullable<T[keyof T]>]>;
1303
0 commit comments