-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
document @types/react #69
Conversation
ADVANCED.md
Outdated
- `SFC` | ||
- `ComponentState` | ||
- `LegacyRef` | ||
- `ReactType` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a source for this? Looking the .d.ts source it seems like they explicitly annotate deprecated types and this is not the case for ReactType
.
ReactType
is pretty useful to cover most types that can be passed to createElement
e.g.
function PassThrough(props: { as: ReactType<any> }) {
const { as: Component } = props;
return <Component />
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope it was just a quick first cut based on my experience. thats why i open up this as a PR so we can discuss :)
My take on the types: Under the
|
you are a stud. will update accordingly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome stuff. Helps a lot to have a general resource we can point to,
ADVANCED.md
Outdated
|
||
Most Commonly Used Interfaces and Types | ||
|
||
- `ReactNode` - anything that is renderable *inside* of JSX, this is NOT the same as what can be returned from a component! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this used to be JSXElement
. master
currently says otherwise:
but React.ReactNode is the set of all possible return values of a component.
Maybe switch from returned from
to rendered by
? It's IMO slightly ambiguous in its current form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes i edited it. ok.
ADVANCED.md
Outdated
- all methods: `createElement`, `cloneElement`, ... are all public and reflect the React runtime API | ||
|
||
|
||
A special note that I discourage the use of most `...Element` types because of how black-boxy `JSX.Element` is. You should almost always assume that anything produced by `React.createElement` is the base type `React.ReactElement`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like this should be under "Namespace: JSX". Also explicitly state who said that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i struggled with where to put this too, but put it in the React namespace because he's actually talking about createElement and cloneElement etc
ADVANCED.md
Outdated
|
||
**Don't use/Internal/Deprecated** | ||
|
||
Anything not listed above are considered internal types and not public. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anything not listed above are considered internal types and not public. | |
Anything not listed above is considered an internal type and not public. If you're not sure you can check out the source of `@types/react`. The types are annotated accordingly. |
Typo suggestion from https://www.dummies.com/education/language-arts/grammar/tricky-grammar-is-it-singular-or-plural/
While it seems like this is true for @deprecated
it doesn't seem like @internal
is used. This is an experimental feature though. Is there some way to verify what types are internal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
according to @ferdaber its not documented what is internal vs not...
Co-Authored-By: sw-yx <[email protected]>
merging for now. |
This example is clear, but what if we want also to extend type definitions of our component with type definitions from passed via E.g. I'm sorry if it's not a proper place to ask this question, I also added more detailed question at SO, but just in case you already stumbled upon with solution, it would be nice to know it ;) Also I think it will be a nice addition to current examples here. Thanks for all your work here, really nice information! |
@havenchyk This should work (with some caveats) with material-ui typings. Explaining what and how this works and what doesn't or needs extra attention needs quite a lot of explaining though. I do want to write a comprehensive summary of polymorphic react components. I'm not sure if this cheatsheet is appropriate though (since this is a very complicated issue) or if this will be part of the material-ui docs or some blog post. If you're just starting out I would highly recommend not using something like The |
@eps1lon I saw the solution in Material UI, as I got it, But anyhow, thanks @eps1lon at least I have a direction for investigation. As for discussion of the pros and cons of the approaches, what the place would you recommend? Can I create a new issue in this repo? /cc @sw-yx |
of course |
part of a larger push to flesh out the Advanced section with useful commentary and best practices on all the provided types
as started here 7b1f1f2 with @ferdaber
i definitely dont have enough experience to write this on my own, we can split this up and/or add commentary here