mirror of
https://github.com/github/codeql-action.git
synced 2026-04-27 01:08:46 +00:00
Add keysTyped and entriesTyped helpers
This commit is contained in:
+14
@@ -1287,3 +1287,17 @@ export async function asyncSome<T>(
|
||||
export function isDefined<T>(value: T | null | undefined): value is T {
|
||||
return value !== undefined && value !== null;
|
||||
}
|
||||
|
||||
/** Like `Object.keys`, but infers the correct key type. */
|
||||
export function keysTyped<T extends Record<string, any>>(
|
||||
object: T,
|
||||
): Array<keyof T> {
|
||||
return Object.keys(object) as Array<keyof T>;
|
||||
}
|
||||
|
||||
/** Like `Object.entries`, but infers the correct key type. */
|
||||
export function entriesTyped<T extends Record<string, any>>(
|
||||
object: T,
|
||||
): Array<[keyof T, NonNullable<T[keyof T]>]> {
|
||||
return Object.entries(object) as Array<[keyof T, NonNullable<T[keyof T]>]>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user