Skip to content

Commit

Permalink
fix: fjerne duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
zenabii committed Jan 7, 2025
1 parent 39ef942 commit 5b454a3
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions packages/jokul/src/utilities/polymorphism/polymorphism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ type ElementTypeProp<ElementType extends React.ElementType> = {
as?: ElementType;
};

type PropsToOmit<
ElementType extends React.ElementType,
Props,
> = keyof (ElementTypeProp<ElementType> & Props);
// type PropsToOmit<ElementType extends React.ElementType, Props> = keyof (ElementTypeProp<ElementType> & Props);

export type PolymorphicProps<
ElementType extends React.ElementType,
Props = {},
Expand All @@ -19,13 +13,11 @@ export type PolymorphicProps<

export type PolymorphicRef<As extends React.ElementType> = React.ComponentPropsWithRef<As>["ref"];

// old utility with ref
export type PolymorphicPropsWithRef<ElementType extends React.ElementType, Props = {}> = PolymorphicProps<
ElementType,
export type PolymorphicComponentPropWithRef<As extends React.ElementType, Props = object> = PolymorphicComponentProp<
As,
Props
> & { ref?: PolymorphicRef<ElementType> };
> & { ref?: PolymorphicRef<As> };

// This is a new type utitlity with ref
// Implementation of reusable polymorphic types
// Explaination: https://blog.logrocket.com/build-strongly-typed-polymorphic-components-react-typescript/
type AsProp<As extends React.ElementType> = { as?: As };
Expand All @@ -35,11 +27,6 @@ type PolymorphicComponentProp<As extends React.ElementType, Props = object> = Re
> &
Omit<React.ComponentPropsWithoutRef<As>, PropsToOmit<As, Props>>;

export type PolymorphicComponentPropWithRef<As extends React.ElementType, Props = object> = PolymorphicComponentProp<
As,
Props
> & { ref?: PolymorphicRef<As> };

// Les https://stackoverflow.com/q/57683303
export type Expand<T> = T extends (...args: infer A) => infer R
? (...args: Expand<A>) => Expand<R>
Expand Down

0 comments on commit 5b454a3

Please sign in to comment.