Comments (6)
yes - am very busy this week so will come back and review this next week. thanks!
from react.
Hi,
Is $ElementProps
still relevant ?
Isn't React.ComponentProps
doing the same job ?
Thanks
from react.
This is very interesting and very appreciated, thank you! can I just ask a clarifying question - in your import Paper from '@material-ui/core/Paper';
example, does that work even if Paper
is untyped?
or are you basically saying, ok, @material-ui/core/Paper
doesn't export Paper
's proptypes, but that's ok, because I can just use $ElementProps
to grab it and do manipulations like &
and Omit
?
Just trying to explain back to you what i think this does. do i have the right idea?
from react.
Yeah thats about right!
Its a nice solution to when you say "I want this prop (eg paperProps) or these props to spread to this component, but not have to decide on the type (be explicit)".
The less explicit about types you are, the safer it will be (imo). Especially when there are any's flying around.
If Paper doesn't have a type because its referencing a JS file (it does though - from material-ui) then TS treats them as any
, so yeah it'l work, like everything does with any
haha.
It just lets you be a bit more expressive, less explicit, and helps in other situations too, especially with making HOCs - when Component or Props types are generic.
Eg - making recompose's defaultProps work properly with TS (we can't preserve currying though, cause no higher kinded types in TS)
import * as Recompose from 'recompose'
export const defaultProps = <
C extends React.ComponentType,
D extends Partial<$ElementProps<C>>
>(
defaults: D,
Component: C
): React.ComponentType<$ElementProps<C> & Partial<D>> =>
Recompose.defaultProps(defaults)(Component);
Make sense?
from react.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions!
from react.
included in #272
from react.
Related Issues (20)
- [Basic] useReducer: type safe dispatcher call HOT 2
- "Props: One or the Other but not Both" does not work HOT 2
- [Question] QUESTION_TITLE_HERE
- [Advanced] Wrapping/Mirroring a Component with ref forwarding
- facing errors
- not working
- Gene Piki wants to pay 0 USD to have this issue fixed
- JSX.Element is Deprecated HOT 11
- [Bug] The logo text is overflowing in small devices it should be truncate like mobile navigation. HOT 5
- Update CSS So that website can be accessible from any device of any width -- Solved HOT 8
- [Basic] Add resources to basic/recommended/talks.md HOT 3
- [Basic] Want to Fix Navbar Text Issue Without Truncating And Decreased Footer Logo Size Responsively For all Devices HOT 3
- Table of Content HOT 2
- Linked article on defaultProps docs is paywalled HOT 3
- add as a contributor? HOT 7
- [Basic] Linting page links are not working HOT 6
- CLASS METHODS AND CLASS PROPERTIES TITLES INTERCHANGED HOT 3
- [Advanced] ISSUE_TITLE_HERE
- [Advanced] Restrict useage of child component only as a child of a particular component HOT 3
- [Basic] Provide some docs on `memo` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react.