Skip to content

Instantly share code, notes, and snippets.

@RubaXa
Created June 16, 2019 08:15
Show Gist options
  • Save RubaXa/9e5f6b7d0138a889c6e9c52b44b75360 to your computer and use it in GitHub Desktop.
Save RubaXa/9e5f6b7d0138a889c6e9c52b44b75360 to your computer and use it in GitHub Desktop.
Optional types
// Вспомогательный тип, который добавляет `undefined`
type Optional<T> = T | undefined;
// Тип, который проверяет на `optional`, путем преобразования входящего
// дженерика в `intersect` и проверкой на вхождение в него `undefined`
type IsOptional<T> = ToIntersect<T> extends undefined ? true : false;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment