0.1.3 • Published 5 years ago

props-of v0.1.3

Weekly downloads
9
License
MIT
Repository
github
Last release
5 years ago

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

npm.io npm.io

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

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

1.0.0

5 years ago

0.1.0

5 years ago