Giter VIP home page Giter VIP logo

Comments (6)

swyxio avatar swyxio commented on April 20, 2024 2

yes - am very busy this week so will come back and review this next week. thanks!

from react.

bsitruk avatar bsitruk commented on April 20, 2024 2

Hi,

Is $ElementProps still relevant ?
Isn't React.ComponentProps doing the same job ?

Thanks

from react.

swyxio avatar swyxio commented on April 20, 2024

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.

dmisdm avatar dmisdm commented on April 20, 2024

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.

stale avatar stale commented on April 20, 2024

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.

swyxio avatar swyxio commented on April 20, 2024

included in #272

from react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.