Skip to content

Instantly share code, notes, and snippets.

@MR-Mostafa
Created November 22, 2023 20:46
Show Gist options
  • Save MR-Mostafa/8be7ad06481748c7097606c5fd0bdea5 to your computer and use it in GitHub Desktop.
Save MR-Mostafa/8be7ad06481748c7097606c5fd0bdea5 to your computer and use it in GitHub Desktop.
Build strongly typed polymorphic components with React and TypeScript - Part 7
/**
* قبل از تغییر
*/
type Props <C extends React.ElementType> = React.PropsWithChildren<ButtonProps<C>> & React.ComponentPropsWithoutRef<C>;
/**
* بعد از تغییر
*/
type Props <C extends React.ElementType> =
React.PropsWithChildren<ButtonProps<C>> &
Omit<React.ComponentPropsWithoutRef<C>, keyof ButtonProps<C>>;
/**
* `Keyof` و `Omit` کاری که انجام دادیم درواقع این بود که با استفاده از
* پراپرتی‌هایی که با موارد تعیین شده توسط ما تداخل یا هم‌پوشانی دارند را حذف می‌کنیم
* به صورت زیر:
* Omit<React.ComponentPropsWithoutRef<C>, keyof ButtonProps<C>>;
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment