You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,6 @@ I thought I should lay out some core principles that we will follow so that this
6
6
7
7
1.**We are a CHEATSHEET above all**: all examples to be as simple as possible, easily searched, and presented for copy-and-paste.
8
8
2.**Collapsible explanations**: No more than 1-2 sentences of explanation, any more than that we put inside `details` tags.
9
-
3.**React + Typescript ONLY**: React's ecosystem is huge, we can't possibly cover it all. This includes Redux. Would encourage people to maintain separate lists for stuff like React + Apollo Graphql, for example.
9
+
3.**React + TypeScript ONLY**: React's ecosystem is huge, we can't possibly cover it all. This includes Redux. Would encourage people to maintain separate lists for stuff like React + Apollo Graphql, for example.
10
10
11
11
That's all I've got! Again, really happy you are thinking about helping out, who knows, the person who you might be helping is yourself in future!
Copy file name to clipboardExpand all lines: README.md
+37-37Lines changed: 37 additions & 37 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
2
-
:wave: This repo is maintained by [@swyx](https://twitter.com/swyx) and [@IslamAttrash](https://twitter.com/IslamAttrash), we're so happy you want to try out Typescript with React! This is meant to be an intermediate guide for React developers familiar with the concepts of Typescript but who are just getting started writing their first React + Typescript apps. If you see anything wrong or missing, please [file an issue](https://github.com/sw-yx/react-typescript-cheatsheet/issues/new)! :+1:
2
+
:wave: This repo is maintained by [@swyx](https://twitter.com/swyx) and [@IslamAttrash](https://twitter.com/IslamAttrash), we're so happy you want to try out TypeScript with React! This is meant to be an intermediate guide for React developers familiar with the concepts of TypeScript but who are just getting started writing their first React + TypeScript apps. If you see anything wrong or missing, please [file an issue](https://github.com/sw-yx/react-typescript-cheatsheet/issues/new)! :+1:
3
3
4
4
Translations: [中文翻译](https://github.com/fi3ework/blog/tree/master/react-typescript-cheatsheet-cn)*maintained by [@fi3ework](https://github.com/fi3ework/blog/tree/master/react-typescript-cheatsheet-cn)*
> In your command line: `create-react-app my-app --scripts-version=@jpavon/react-scripts-ts`
81
81
82
82
83
-
2.<https://github.com/sw-yx/create-react-app-parcel-typescript> sets up a React + Typescript app with Parcel :)
84
-
3.<https://github.com/basarat/typescript-react/tree/master/01%20bootstrap> for manual setup of React + Typescript + Webpack + Babel
83
+
2.<https://github.com/sw-yx/create-react-app-parcel-typescript> sets up a React + TypeScript app with Parcel :)
84
+
3.<https://github.com/basarat/typescript-react/tree/master/01%20bootstrap> for manual setup of React + TypeScript + Webpack + Babel
85
85
86
-
In particular, make sure that you have `@types/react` and `@types/react-dom` installed. [Read more about the DefinitelyTyped project if you are unfamiliar](https://definitelytyped.org/). There are also many React + Typescript boilerplates, please see [our Resources list below](https://github.com/sw-yx/react-typescript-cheatsheet#recommended-react--typescript-codebases-to-learn-from).
86
+
In particular, make sure that you have `@types/react` and `@types/react-dom` installed. [Read more about the DefinitelyTyped project if you are unfamiliar](https://definitelytyped.org/). There are also many React + TypeScript boilerplates, please see [our Resources list below](https://github.com/sw-yx/react-typescript-cheatsheet#recommended-react--typescript-codebases-to-learn-from).
87
87
88
88
## Import React
89
89
@@ -92,7 +92,7 @@ import * as React from 'react';
92
92
import*asReactDOMfrom'react-dom';
93
93
```
94
94
95
-
In [TypeScript 2.7+](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html), you can run Typescript with `--allowSyntheticDefaultImports` (or add `"allowSyntheticDefaultImports": true` to tsconfig) to import like in regular jsx:
95
+
In [TypeScript 2.7+](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-7.html), you can run TypeScript with `--allowSyntheticDefaultImports` (or add `"allowSyntheticDefaultImports": true` to tsconfig) to import like in regular jsx:
Within Typescript, `React.Component` is a generic type (aka `React.Component<PropType, StateType>`), so you actually want to provide it with prop and (optionally) state types:
148
+
Within TypeScript, `React.Component` is a generic type (aka `React.Component<PropType, StateType>`), so you actually want to provide it with prop and (optionally) state types:
149
149
150
150
```tsx
151
151
classAppextendsReact.Component<{
@@ -306,13 +306,13 @@ class App extends React.Component<AppProps, AppState> {
306
306
307
307
## Types or Interfaces?
308
308
309
-
`interface`s are different from `type`s in Typescript, but they can be used for very similar things as far as common React uses cases are concerned. Here's a helpful rule of thumb:
309
+
`interface`s are different from `type`s in TypeScript, but they can be used for very similar things as far as common React uses cases are concerned. Here's a helpful rule of thumb:
310
310
311
311
- always use `interface` for public API's definition when authoring a library or 3rd party ambient type definitions.
312
312
313
313
- consider using `type` for your React Component Props and State, because it is more constrained.
314
314
315
-
[You can read more about the edge cases of using types and interfaces here](https://medium.com/@martin_hotell/interface-vs-type-alias-in-typescript-2-7-2a8f1777af4c). Note there have been significant changes since Typescript 2.1.
315
+
[You can read more about the edge cases of using types and interfaces here](https://medium.com/@martin_hotell/interface-vs-type-alias-in-typescript-2-7-2a8f1777af4c). Note there have been significant changes since TypeScript 2.1.
316
316
317
317
[Something to add? File an issue](https://github.com/sw-yx/react-typescript-cheatsheet/issues/new).
318
318
@@ -548,17 +548,17 @@ This example is based on the [Event Bubbling Through Portal](https://reactjs.org
548
548
549
549
[Something to add? File an issue](https://github.com/sw-yx/react-typescript-cheatsheet/issues/new).
550
550
551
-
# Section 4: Useful Patterns by Typescript Version
551
+
# Section 4: Useful Patterns by TypeScript Version
552
552
553
-
Typescript Versions often introduce new ways to do things; this section helps current users of React + Typescript upgrade Typescript versions and explore patterns commonly used by Typescript + React apps and libraries. This may have duplications with other sections; if you spot any discrepancies, [file an issue](https://github.com/sw-yx/react-typescript-cheatsheet/issues/new)!
553
+
TypeScript Versions often introduce new ways to do things; this section helps current users of React + TypeScript upgrade TypeScript versions and explore patterns commonly used by TypeScript + React apps and libraries. This may have duplications with other sections; if you spot any discrepancies, [file an issue](https://github.com/sw-yx/react-typescript-cheatsheet/issues/new)!
554
554
555
-
*Typescript version guides before 2.9 are unwritten, please feel free to send a PR!*
555
+
*TypeScript version guides before 2.9 are unwritten, please feel free to send a PR!*
@@ -601,11 +601,11 @@ For typing API's to force type checks - *should we include this?*
601
601
602
602
# Section 5: Misc. Concerns
603
603
604
-
Sometimes writing React isn't just about React. While we don't focus on other libraries like Redux (seebelowformoreonthat), here are some tips on other common concerns when making apps with React + Typescript.
604
+
Sometimes writing React isn't just about React. While we don't focus on other libraries like Redux (seebelowformoreonthat), here are some tips on other common concerns when making apps with React + TypeScript.
@@ -773,7 +773,7 @@ Please contribute on this topic! [We have an ongoing issue here with some refere
773
773
774
774
# TroubleshootingHandbook:Types
775
775
776
-
Facingweirdtypeerrors?Youaren't alone. This is the worst part of using Typescript with React. Try to avoid typing with `any` as much as possible to experience the full benefits of typescript. Instead, let'strytobefamiliarwithsomeofthecommonstrategiestosolvetheseissues.
776
+
Facingweirdtypeerrors?Youaren't alone. This is the worst part of using TypeScript with React. Try to avoid typing with `any` as much as possible to experience the full benefits of typescript. Instead, let'strytobefamiliarwithsomeofthecommonstrategiestosolvetheseissues.
777
777
778
778
## Uniontypes
779
779
@@ -827,7 +827,7 @@ This is not yet written. Please PR or [File an issue](https://github.com/sw-yx/r
@@ -1071,7 +1071,7 @@ Please open an issue and discuss if there are better recommended choices. I like
1071
1071
1072
1072
# TroubleshootingHandbook: Bugsinofficialtypings
1073
1073
1074
-
Ifyourunintobugswithyourlibrary's official typings, you can copy them locally and tell Typescript to use your local version using the "paths" field. In your `tsconfig.json`:
1074
+
Ifyourunintobugswithyourlibrary's official typings, you can copy them locally and tell TypeScript to use your local version using the "paths" field. In your `tsconfig.json`:
- <https://github.com/piotrwitek/react-redux-typescript-guide> - **HIGHLY HIGHLY RECOMMENDED**, i wrote this repo before knowing about this one, this has a lot of stuff I don't cover, including **REDUX** and **JEST**.
- [Basarat's Typescript gitbook has a React section](https://basarat.gitbooks.io/typescript/content/docs/jsx/react.html) with an Egghead.io course as well.
- [Basarat's TypeScript gitbook has a React section](https://basarat.gitbooks.io/typescript/content/docs/jsx/react.html) with an Egghead.io course as well.
1138
1138
- [CharlesBryant's gitbook](https://charleslbryant.gitbooks.io/hello-react-and-typescript/content/) 2yrs old and on the more basic side but has sample code and IDE advice.
1139
1139
- [TypeScriptReactStarterTemplatebyMicrosoft](https://github.com/Microsoft/TypeScript-React-Starter) A starter template for TypeScript and React with a detailed README describing how to use the two together.
0 commit comments