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
@@ -255,7 +254,6 @@ You should also check [the new TypeScript docs for official descriptions between
255
254
# Section 2: Getting Started
256
255
257
256
<!--START-SECTION:function-components-->
258
-
259
257
## Function Components
260
258
261
259
These can be written as normal functions that take a `props` argument and return a JSX element.
@@ -377,7 +375,6 @@ const MyArrayComponent = () => (Array(5).fill(<div />) as any) as JSX.Element;
377
375
<!--END-SECTION:function-components-->
378
376
379
377
<!--START-SECTION:hooks-->
380
-
381
378
## Hooks
382
379
383
380
Hooks are [supported in `@types/react` from v16.8 up](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/a05cc538a42243c632f054e42eab483ebf1560ab/types/react/index.d.ts#L800-L1031).
@@ -656,7 +653,6 @@ If you are writing a React Hooks library, don't forget that you should also expo
656
653
<!--END-SECTION:hooks-->
657
654
658
655
<!--START-SECTION:class-components-->
659
-
660
656
## Class Components
661
657
662
658
Within TypeScript, `React.Component` is a generic type (aka `React.Component<PropType, StateType>`), so you want to provide it with (optional) prop and state type parameters:
@@ -831,7 +827,6 @@ class Comp extends React.PureComponent<Props, State> {
831
827
<!--END-SECTION:class-components-->
832
828
833
829
<!--START-SECTION:default-props-->
834
-
835
830
## You May Not Need `defaultProps`
836
831
837
832
As per [this tweet](https://twitter.com/dan_abramov/status/1133878326358171650), defaultProps will eventually be deprecated. You can check the discussions here:
@@ -1042,7 +1037,6 @@ The problem with this approach is it causes complex issues with the type inferen
1042
1037
<!--END-SECTION:default-props-->
1043
1038
1044
1039
<!--START-SECTION:basic-type-examples-->
1045
-
1046
1040
## Typing Component Props
1047
1041
1048
1042
This is intended as a basic orientation and reference for React developers familiarizing with TypeScript.
@@ -1266,7 +1260,6 @@ class Comp extends React.PureComponent<Props, State> {
1266
1260
<!--END-SECTION:get-derived-state-from-props-->
1267
1261
1268
1262
<!--START-SECTION:forms-and-events-->
1269
-
1270
1263
## Forms and Events
1271
1264
1272
1265
If performance is not an issue (and it usually isn't!), inlining handlers is easiest as you can just use [type inference and contextual typing](https://www.typescriptlang.org/docs/handbook/type-inference.html#contextual-typing):
@@ -1368,7 +1361,6 @@ Of course, if you're making any sort of significant form, [you should use Formik
_Not written yet._ watch <https://github.com/sw-yx/fresh-async-react> for more on React Suspense and Time Slicing.
@@ -1889,7 +1877,6 @@ _Not written yet._ watch <https://github.com/sw-yx/fresh-async-react> for more o
1889
1877
<!--END-SECTION:concurrent-->
1890
1878
1891
1879
<!--START-SECTION:types-->
1892
-
1893
1880
# Troubleshooting Handbook: Types
1894
1881
1895
1882
> ⚠️ Have you read [the TypeScript FAQ](https://github.com/microsoft/TypeScript/wiki/FAQ?) Your answer might be there!
@@ -2430,7 +2417,6 @@ For more information on creating type definitions for class components, you can
2430
2417
<!--END-SECTION:types-->
2431
2418
2432
2419
<!--START-SECTION:operators-->
2433
-
2434
2420
# Troubleshooting Handbook: Operators
2435
2421
2436
2422
- `typeof` and `instanceof`: type query used for refinement
@@ -2454,7 +2440,6 @@ Conditional Types are a difficult topic to get around so here are some extra res
2454
2440
<!--END-SECTION:operators-->
2455
2441
2456
2442
<!--START-SECTION:utilities-->
2457
-
2458
2443
# Troubleshooting Handbook: Utilities
2459
2444
2460
2445
These are all built in, [see source in es5.d.ts](https://github.com/microsoft/TypeScript/blob/2c458c0d1ccb96442bca9ce43aa987fb0becf8a9/src/lib/es5.d.ts#L1401-L1474):
@@ -2476,7 +2461,6 @@ These are all built in, [see source in es5.d.ts](https://github.com/microsoft/Ty
2476
2461
<!--END-SECTION:utilities-->
2477
2462
2478
2463
<!--START-SECTION:ts-config-->
2479
-
2480
2464
# Troubleshooting Handbook: tsconfig.json
2481
2465
2482
2466
You can find [all the Compiler options in the TypeScript docs](https://www.typescriptlang.org/docs/handbook/compiler-options.html). [The new TS docs also has per-flag annotations of what each does](https://www.typescriptlang.org/tsconfig#allowSyntheticDefaultImports). This is the setup I roll with for APPS (not libraries - for libraries you may wish to see the settings we use in `tsdx`):
@@ -2528,7 +2512,6 @@ Compilation speed grows linearly with size of codebase. For large projects, you
2528
2512
<!--END-SECTION:ts-config-->
2529
2513
2530
2514
<!--START-SECTION:official-typings-bugs-->
2531
-
2532
2515
# Troubleshooting Handbook: Fixing bugs in official typings
2533
2516
2534
2517
If you run into bugs with your library's official typings, you can copy them locally and tell TypeScript to use your local version using the "paths" field. In your `tsconfig.json`:
@@ -2595,7 +2578,6 @@ You can see examples of these included in the built in type declarations in the
2595
2578
<!--END-SECTION:official-typings-bugs-->
2596
2579
2597
2580
<!--START-SECTION:non-ts-files-->
2598
-
2599
2581
# Time to Really Learn TypeScript
2600
2582
2601
2583
Believe it or not, we have only barely introduced TypeScript here in this cheatsheet. If you are still facing TypeScript troubleshooting issues, it is likely that your understanding of TS is still too superficial.
@@ -2616,7 +2598,6 @@ It is worth mentioning some resources to help you get started:
2616
2598
<!--END-SECTION:non-ts-files-->
2617
2599
2618
2600
<!--START-SECTION:resources-->
2619
-
2620
2601
# Other React + TypeScript resources
2621
2602
2622
2603
- me! <https://twitter.com/swyx>
@@ -2639,7 +2620,6 @@ It is worth mentioning some resources to help you get started:
2639
2620
<!--END-SECTION:resources-->
2640
2621
2641
2622
<!--START-SECTION:editor-integration-->
2642
-
2643
2623
# Editor Tooling and Integration
2644
2624
2645
2625
- VSCode
@@ -2664,7 +2644,6 @@ You may also wish to use alternative logos - [jsx-tsx-logos](https://github.com/
2664
2644
<!--END-SECTION:editor-integration-->
2665
2645
2666
2646
<!--START-SECTION:linting-->
2667
-
2668
2647
# Linting
2669
2648
2670
2649
> ⚠️Note that [TSLint is now in maintenance and you should try to use ESLint instead](https://medium.com/palantir/tslint-in-2019-1a144c2317a9). If you are interested in TSLint tips, please check this PR from [@azdanov](https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/pull/14). The rest of this section just focuses on ESLint. [You can convert TSlint to ESlint with this tool](https://github.com/typescript-eslint/tslint-to-eslint-config).
@@ -2795,7 +2774,6 @@ If you're looking for information on Prettier, check out the [Prettier](https://
2795
2774
<!--END-SECTION:other-resources-->
2796
2775
2797
2776
<!--START-SECTION:talks-->
2798
-
2799
2777
# Recommended React + TypeScript talks
2800
2778
2801
2779
- [Ultimate React Component Patterns with TypeScript](https://www.youtube.com/watch?v=_PBQ3if6Fmg), by Martin Hochel, GeeCon Prague 2018
@@ -2804,7 +2782,6 @@ If you're looking for information on Prettier, check out the [Prettier](https://
2804
2782
<!--END-SECTION:talks-->
2805
2783
2806
2784
<!--START-SECTION:learn-ts-->
2807
-
2808
2785
# Time to Really Learn TypeScript
2809
2786
2810
2787
Believe it or not, we have only barely introduced TypeScript here in this cheatsheet. If you are still facing TypeScript troubleshooting issues, it is likely that your understanding of TS is still too superficial.
@@ -2825,7 +2802,6 @@ It is worth mentioning some resources to help you get started:
2825
2802
<!--END-SECTION:learn-ts-->
2826
2803
2827
2804
<!--START-SECTION:examples-->
2828
-
2829
2805
# Example App
2830
2806
2831
2807
- [Create React App TypeScript Todo Example 2020](https://github.com/laststance/create-react-app-typescript-todo-example-2020)
0 commit comments