Skip to content

Add TypeScript-related pages to new docs #5960

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

Closed
markerikson opened this issue Apr 25, 2023 · 3 comments
Closed

Add TypeScript-related pages to new docs #5960

markerikson opened this issue Apr 25, 2023 · 3 comments

Comments

@markerikson
Copy link
Contributor

markerikson commented Apr 25, 2023

Per https://twitter.com/mattpocockuk/status/1650611319312113665 , the new React docs currently do not provide any information on using React with TypeScript:

One super-frustrating thing about libraries that don't ship TypeScript types themselves (i.e. React) is that they don't bother documenting their types.

In React, super important types like ComponentProps aren't in the official docs, and a lot of devs don't know about them 🤯

When we did a survey of /r/reactjs in 2019, about 48% of respondents said they were using TS with React, and all the anecdata I've read since then says that percentage is now way higher.

It would be extremely helpful if the docs had some kind of official page on React+TS usage.

The current de-facto React+TS reference is https://react-typescript-cheatsheet.netlify.app/ , which has numerous pages on setup, basic usage, and advanced usage, as well as an abbreviated page listing some of the utility types such as ComponentProps.

There's enough material there that I don't expect all of it to get added to the React docs. But, at a minimum, there ought to be at least one "TS Usage" page that covers things like:

  • Setup and needing to install the @types/react* packages
  • Typing function components
  • Signatures for the major hooks
  • Typing event handlers

and then points over to the React+TS Cheatsheet for further reference.

I could see potential for having more than one page, such as splitting it across "Setup", "Basic Usage", "Advanced Usage", and "TS Types API Reference", but that would be a stretch goal. It would also be nice to have TS information on the individual API reference pages at some point as well, but that's also somewhat of a stretch goal.

Dan mentioned that at some point the React team might want to do cleanup on the TS types to better reflect the React team's view of those concepts. That can be done later, but I strongly think that there needs to be some TS usage material added to the React docs today to provide guidance to the community on how to use React+TS properly.

Would the React team be open to accepting a PR adding a "TS Usage" page along these lines?

Note As anecdata, I just pulled up download stats for React, ReactDOM, and their types:
image
Somehow @types/react is being downloaded 9% more than react. I have no explanation for this 🤷‍♂️ :)
But I do think it's realistic that @types/react-dom is 75% of react-dom downloads.

@CalleEklund
Copy link

I'll be happy to work on this and give a first draft. I'm new to contributing to opensource project but do have experience in react and typescript.

@rickhanlonii
Copy link
Member

Thanks for the suggestion, let's do it!

@orta graciously volunteered to create the first draft, let's start there and iterate ✨

@rickhanlonii
Copy link
Member

Merged, thanks for the suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants