INNER CODE UNIT · TypeScript

hasOwn

vercel/storage · packages/global-config/src/utils/index.ts:21

export function hasOwn<X extends object, Y extends PropertyKey>(
  obj: X,
  prop: Y,
): obj is X & Record<Y, unknown> {
  return Object.hasOwn(obj, prop);
}

export function pick<T, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {
  const ret: Partial<T> = {};
  keys.forEach((key) => {
    ret[key] = obj[key];
  });
  return ret as Pick<T, K>;
}

export function assertIsKey(key: unknown): asserts key is string {
  if (typeof key !== 'string') {
    throw new Error('@vercel/global-config: Expected key to be a string');

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…