renovate/lib/util/object.ts
renovate[bot] 5109f9b794
chore(deps): update dependency typescript to v4.8.4 (#17988)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jamie Magee <jamie.magee@gmail.com>
2022-10-07 06:15:49 +00:00

13 lines
382 B
TypeScript

/**
* This is a workaround helper to allow the usage of 'unknown' in
* a type-guard function while checking that keys exist.
*
* @see https://github.com/microsoft/TypeScript/issues/21732
* @see https://stackoverflow.com/a/58630274
*/
export function hasKey<K extends string, T>(
k: K,
o: T
): o is T & Record<K, unknown> {
return o && typeof o === 'object' && k in o;
}