New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

props-of

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

props-of

Infer types of props from React component

latest
Source
npmnpm
Version
0.1.3
Version published
Maintainers
1
Created
Source

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

Keywords

react

FAQs

Package last updated on 15 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts