КодНе начато
Задача на типы: ровно один проп-флаг
Сложность: сложный
Постройте ExclusiveFlags<K>, чтобы <Sign value={n} isPositive /> принимал ровно один из isPositive, isNegative, isZero: ни одного или два — ошибка компиляции. Подсказка: по одному члену объединения на ключ, а остальные ключи типизированы как ?: never.
Показать эталонное решение
// Build one object type per key, then index with [K] to turn the map into a union.// The other keys are `?: never`, so passing a second flag (any value but undefined) is an error.export type ExclusiveFlags<K extends PropertyKey> = { [P in K]: { [Q in P]: boolean } & { [Q in Exclude<K, P>]?: never };}[K];
export type SignProps = { value: number } & ExclusiveFlags<'isPositive' | 'isNegative' | 'isZero'>;
Ctrl Enter