Dev Highlights

Доки по разработке

This project is maintained by teniryte

Параметры по умолчанию в дженериках

Принципы

Пример

function firstOrNull<T = string>(array: T[]): T | null {
  return array.length === 0 ? null : array[0];
}

interface Component<TName = string, TProps = any> {
  name: TName;
  props: TProps;
  log: () => void;
}

const button: Component = {
  name: 'Button',
  props: { text: 'Save' },
  log: () => console.log('Save button'),
};

Практика