mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
13 lines
377 B
TypeScript
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;
|
|
}
|