Skip to content

Commit

Permalink
Simplify props types
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed Jun 21, 2024
1 parent d60ed6a commit 27a79e8
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packages/@headlessui-react/src/utils/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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<T extends RenderFeatures> = XOR<
PropsForFeature<T, RenderFeatures.Static, { static?: boolean }>,
PropsForFeature<T, RenderFeatures.RenderStrategy, { unmount?: boolean }>
type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (x: infer R) => any
? R
: never

type PropsForFeaturesImpl<T> = 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<T extends RenderFeatures> = PropsForFeaturesImpl<
UnionToIntersection<T>
>

export function render<TFeature extends RenderFeatures, TTag extends ElementType, TSlot>({
Expand Down

0 comments on commit 27a79e8

Please sign in to comment.