question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[typescript] Better type annotations for unstyled `components` and `componentsProps` props

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

Summary 💡

Improve developer experience by providing type information in componentsProps when a component/element is passed in the respective components field.

Once a developer populates the components.X field, they will see intellisense hints in componentsProps.x with all the props available to pass to the X component.

Examples 🌈

Preliminary work has been done in: https://github.com/michaldudak/material-ui/commit/a9f37babc2b3dccde59e325ffc316a7bfcb49aab

The problem with this solution is that it causes PropTypes to be generated incorrectly. For components fields, the expected prop type would be PropTypes.elementType, but a union of all intrinsic element names and PropTypes.func is generated. This is problematic when a class based component, or a one created with React.forwardRef is passed in.

Motivation 🔦

Having detailed hints in intellisense and the ability to check types before runtime will lead to increased developer happiness and productivity. As an application developer myself, I value well-crafted type definitions that help during development.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
mnajdovacommented, Jul 28, 2021

Yeah, let’s go with it. Developers can anyway augment the props interface if they want to make it stricter.

1reaction
michaldudakcommented, Jul 27, 2021

@mnajdova You were using {as, styleProps} in the first unstyled components. Do you have an opinion about using Record<string, any> instead, as proposed here?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typing Component Props - React TypeScript Cheatsheets
A list of TypeScript types you will likely use in a React+TypeScript app: type AppProps = { message: string; count: number; disabled: boolean;...
Read more >
How to Statically Type React Components with TypeScript
In this guide, you will learn how to statically type React.js components using the compile-to-JavaScript language, TypeScript.
Read more >
Using styled-components and Props With Typescript React
This is a basic rule of Typescript and you can read more about it from ... Next, You install styled-components and the type...
Read more >
Build strongly typed polymorphic components with React and ...
Learn how to build strongly typed polymorphic React components with TypeScript, using familiar Chakra UI and MUI component props as guides.
Read more >
[SelectUnstyled] TypeScript issues #30870 - mui/material-ui
I am trying to build custom Select component using the SelectUnstyled and Tailwind CSS. Some improvements that we should make:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found