Skip to content

Instantly share code, notes, and snippets.

@RubaXa
Created August 27, 2019 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RubaXa/dc9a96253b07a4233e7c2603ee8efe35 to your computer and use it in GitHub Desktop.
Save RubaXa/dc9a96253b07a4233e7c2603ee8efe35 to your computer and use it in GitHub Desktop.
TrueSlots. SlotProp.
// Функциональный слот
type SlotWithValue< S extends SlotPropType, V, R > = (parent: S, val: V) => R
// Обычный слот
type SlotWithoutValue< S extends SlotPropType > = (parent: S) => S
// 🎰 А теперь в зависимости от того, какая у нас S-спека
// возвращаем обыччный слот, либо функциональный
type SlotProp< S extends SlotPropType > = null | (
S extends (value: infer V) => infer R // если S — функция
? SlotWithValue< S, V, R > | R
: SlotWithoutValue< S > | S
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment