TypeScript Pick и Record

Определение типов:

type Pick<T, K extends keyof T> = {
    [P in K]: T[P];
}
type Record<K extends string, T> = {
    [P in K]: T;
}

Pick

interface Dog {
  id?: number;
  name: string;
  weight: number;
  age: number;
}

type Doggy = Pick<Dog, 'id' | 'name' >;

// эквивалентно
type Doggy = {
  id?: number;
  name: string;
}

Record

type ThreeDogProps = Record<'prop1' | 'prop2' | 'prop3', Dog>;

// эквивалентно
type ThreeDogProps = {
  prop1: Dog;
  prop2: Dog;
  prop3: Dog;
}

Похожие записи

JS. Get query param

function getQueryParam(item) {
  var svalue = window.location.search.match(new RegExp('[\?\&]' + item + '=([^\&]*)(\&?)', 'i'));
  return svalue ? svalue[1] : svalue;
}

// /foo/bar/baz.html?lang=ru
var lang = getQueryParam('lang') || 'en';