This package has been deprecated

Author message:

Please use React.ComponentProps<T> defined in @types/react :)

props-of
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

Deprecated

You don't need to install anything. Use React.ComponentProps<T> defined in @types/react 😉


Infer types of props from React component

Contents

📦 How to get the code?

This is package is one line of code, so you can either install it or copy-paste it 😉

🔌 Installation

yarn add --dev props-of

📃 Source

export type PropsOf<T> = T extends React.ComponentType<infer P> ? P : never;

❔ Why

And now we can use it for props of parent component.

type MenuLinkProps = {
  to: LinkProps['to'];
} & PropsOf<typeof Menu.Item>;
 
const MenuLink = ({ children, to, ...rest }: MenuLinkProps) => (
  <Menu.Item {...rest}>
    <Link to={to}>{children}</Link>
  </Menu.Item>
);

📚 I want to know more

You can learn about infer and conditional types at
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html

Readme

Keywords

Package Sidebar

Install

npm i props-of

Weekly Downloads

0

Version

0.1.3

License

MIT

Unpacked Size

2.85 kB

Total Files

5

Last publish

Collaborators

  • hasparus