From 27a79e8cc45deaa52d3cb849f274e6a65e35c3b0 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 21 Jun 2024 13:06:17 -0400 Subject: [PATCH] Simplify props types --- .../@headlessui-react/src/utils/render.ts | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/@headlessui-react/src/utils/render.ts b/packages/@headlessui-react/src/utils/render.ts index f3eda31e10..eb88434597 100644 --- a/packages/@headlessui-react/src/utils/render.ts +++ b/packages/@headlessui-react/src/utils/render.ts @@ -11,7 +11,7 @@ import { type ReactElement, type Ref, } from 'react' -import type { Expand, Props, XOR, __ } from '../types' +import type { Expand, Props } from '../types' import { classNames } from './class-names' import { match } from './match' @@ -44,13 +44,22 @@ type PropsForFeature< TPassedInFeatures extends RenderFeatures, TForFeature extends RenderFeatures, TProps, -> = { - [P in TPassedInFeatures]: P extends TForFeature ? TProps : __ -}[TPassedInFeatures] +> = TPassedInFeatures extends TForFeature ? TProps : {} -export type PropsForFeatures = XOR< - PropsForFeature, - PropsForFeature +type UnionToIntersection = (T extends any ? (x: T) => any : never) extends (x: infer R) => any + ? R + : never + +type PropsForFeaturesImpl = T extends RenderFeatures.Static & RenderFeatures.RenderStrategy + ? { static?: never; unmount?: never } + : T extends RenderFeatures.RenderStrategy + ? { unmount?: boolean } + : T extends RenderFeatures.Static + ? { static?: boolean } + : {} + +export type PropsForFeatures = PropsForFeaturesImpl< + UnionToIntersection > export function render({