renovate/lib/util/object.ts
2020-11-24 11:09:40 +01:00

13 lines
377 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 typeof o === 'object' && k in o;
}