|
63 | 63 |
|
64 | 64 | <summary><b>Expand Table of Contents</b></summary>
|
65 | 65 |
|
66 |
| -- [Section 1: Setup TypeScript with React](#section-1-setup-typescript-with-react) |
| 66 | +- [Section 1: Setup TypeScript with React](#section-1--setup-typescript-with-react) |
| 67 | + <!--START-SECTION:setup-toc--> |
67 | 68 | - [Prerequisites](#prerequisites)
|
| 69 | + - [VS Code Extensions](#vs-code-extensions) |
68 | 70 | - [React + TypeScript Starter Kits](#react--typescript-starter-kits)
|
69 | 71 | - [Import React](#import-react)
|
70 |
| -- [Section 2: Getting Started](#section-2-getting-started) |
| 72 | + - [Video Tutorial](#video-tutorial)<!--END-SECTION:setup-toc--> |
| 73 | +- [Section 2: Getting Started](#section-2--getting-started) |
71 | 74 | - [Function Components](#function-components)
|
72 | 75 | - [Hooks](#hooks)
|
73 | 76 | - [useState](#usestate)
|
74 | 77 | - [useReducer](#usereducer)
|
75 |
| - - [useEffect](#useeffect--uselayouteffect) |
| 78 | + - [useEffect / useLayoutEffect](#useeffect---uselayouteffect) |
76 | 79 | - [useRef](#useref)
|
| 80 | + - [Option 1: DOM element ref](#option-1--dom-element-ref) |
| 81 | + - [Option 2: Mutable value ref](#option-2--mutable-value-ref) |
| 82 | + - [See also](#see-also) |
77 | 83 | - [useImperativeHandle](#useimperativehandle)
|
78 | 84 | - [Custom Hooks](#custom-hooks)
|
| 85 | + - [More Hooks + TypeScript reading:](#more-hooks---typescript-reading-) |
| 86 | + - [Example React Hooks + TypeScript Libraries:](#example-react-hooks---typescript-libraries-) |
79 | 87 | - [Class Components](#class-components)
|
80 |
| - - [You May Not Need `defaultProps`](#you-may-not-need-defaultprops) |
81 |
| - - [Typing `defaultProps`](#typing-defaultprops) |
| 88 | + - [Typing getDerivedStateFromProps](#typing-getderivedstatefromprops) |
| 89 | + - [You May Not Need `defaultProps`](#you-may-not-need--defaultprops-) |
| 90 | + - [Typing `defaultProps`](#typing--defaultprops-) |
82 | 91 | - [Consuming Props of a Component with defaultProps](#consuming-props-of-a-component-with-defaultprops)
|
83 | 92 | - [Problem Statement](#problem-statement)
|
84 | 93 | - [Solution](#solution)
|
85 | 94 | - [Misc Discussions and Knowledge](#misc-discussions-and-knowledge)
|
| 95 | + - [Typing Component Props](#typing-component-props) |
86 | 96 | - [Basic Prop Types Examples](#basic-prop-types-examples)
|
87 | 97 | - [Useful React Prop Type Examples](#useful-react-prop-type-examples)
|
88 |
| - - [getDerivedStateFromProps](#getderivedstatefromprops) |
89 |
| - - [Forms and Events](#forms-and-events) |
90 |
| - - [Context](#context) |
91 |
| - - [Basic Example](#basic-example) |
92 |
| - - [Extended Example](#extended-example) |
93 |
| - - [forwardRef/createRef](#forwardrefcreateref) |
94 |
| - - [Portals](#portals) |
95 |
| - - [Error Boundaries](#error-boundaries) |
96 |
| - - [Option 1: Using react-error-boundary](#option-1-using-react-error-boundary) |
97 |
| - - [Options 2: Writing your custom error boundary component](#options-2-writing-your-custom-error-boundary-component) |
98 |
| - - [Concurrent React/React Suspense](#concurrent-reactreact-suspense) |
99 |
| -- [Troubleshooting Handbook: Types](#troubleshooting-handbook-types) |
100 |
| - - [Union Types and Type Guarding](#union-types-and-type-guarding) |
101 |
| - - [Optional Types](#optional-types) |
102 |
| - - [Enum Types](#enum-types) |
103 |
| - - [Type Assertion](#type-assertion) |
104 |
| - - [Simulating Nominal Types](#simulating-nominal-types) |
105 |
| - - [Intersection Types](#intersection-types) |
106 |
| - - [Union Types](#union-types) |
107 |
| - - [Overloading Function Types](#overloading-function-types) |
108 |
| - - [Using Inferred Types](#using-inferred-types) |
109 |
| - - [Using Partial Types](#using-partial-types) |
110 |
| - - [The Types I need weren't exported!](#the-types-i-need-werent-exported) |
111 |
| - - [The Types I need don't exist!](#the-types-i-need-dont-exist) |
112 |
| - - [Slapping `any` on everything](#slapping-any-on-everything) |
113 |
| - - [Autogenerate types](#autogenerate-types) |
114 |
| - - [Typing Exported Hooks](#typing-exported-hooks) |
115 |
| - - [Typing Exported Components](#typing-exported-components) |
116 |
| -- [Troubleshooting Handbook: Operators](#troubleshooting-handbook-operators) |
117 |
| -- [Troubleshooting Handbook: Utilities](#troubleshooting-handbook-utilities) |
118 |
| -- [Troubleshooting Handbook: tsconfig.json](#troubleshooting-handbook-tsconfigjson) |
119 |
| -- [Troubleshooting Handbook: Fixing bugs in official typings](#troubleshooting-handbook-fixing-bugs-in-official-typings) |
120 |
| -- [Troubleshooting Handbook: Globals, Images and other non-TS files](#troubleshooting-handbook-globals-images-and-other-non-ts-files) |
121 |
| -- [Other React + TypeScript resources](#other-react--typescript-resources) |
122 |
| -- [Editor Tooling and Integration](#editor-tooling-and-integration) |
123 |
| -- [Linting](#linting) |
124 |
| -- [Other React + TypeScript resources](#other-react--typescript-resources-1) |
125 |
| -- [Recommended React + TypeScript talks](#recommended-react--typescript-talks) |
126 |
| -- [Time to Really Learn TypeScript](#time-to-really-learn-typescript) |
127 |
| -- [Example App](#example-app) |
128 |
| -- [My question isn't answered here!](#my-question-isnt-answered-here) |
129 |
| - - [Contributors](#contributors) |
130 |
| - <!--START-SECTION:setup-toc--> |
131 |
| - - [Prerequisites](#prerequisites) |
132 |
| - - [VS Code Extensions](#vs-code-extensions) |
133 |
| - - [React + TypeScript Starter Kits](#react--typescript-starter-kits) |
134 |
| - - [Import React](#import-react) |
135 |
| - - [Video Tutorial](#video-tutorial)<!--END-SECTION:setup-toc--> |
136 |
| -- [Section 2: Getting Started](#section-2-getting-started) |
137 |
| - - [Function Components](#function-components) |
138 |
| - - [Hooks](#hooks) |
139 |
| - - [Class Components](#class-components) |
140 |
| - - [Typing defaultProps](#typing-defaultprops) |
141 |
| - - [Types or Interfaces?](#types-or-interfaces) |
142 |
| - - [Basic Prop Types Examples](#basic-prop-types-examples) |
143 |
| - - [Useful React Prop Type Examples](#useful-react-prop-type-examples) |
144 |
| - - [getDerivedStateFromProps](#getDerivedStateFromProps) |
145 |
| - - [Forms and Events](#forms-and-events) |
146 |
| - - [Context](#context) |
147 |
| - - [forwardRef/createRef](#forwardrefcreateref) |
148 |
| - - [Portals](#portals) |
149 |
| - - [Error Boundaries](#error-boundaries) |
150 |
| - - [Concurrent React/React Suspense](#concurrent-reactreact-suspense) |
151 |
| -- [Basic Troubleshooting Handbook: Types](#basic-troubleshooting-handbook-types) |
| 98 | + - [Types or Interfaces?](#types-or-interfaces-) |
| 99 | + - [TL;DR](#tl-dr) |
| 100 | + - [More Advice](#more-advice) |
| 101 | + - [Useful table for Types vs Interfaces](#useful-table-for-types-vs-interfaces) |
| 102 | +- [getDerivedStateFromProps](#getderivedstatefromprops) |
| 103 | +- [Forms and Events](#forms-and-events) |
| 104 | +- [List of event types](#list-of-event-types) |
| 105 | +- [Context](#context) |
| 106 | +- [Basic Example](#basic-example) |
| 107 | +- [Extended Example](#extended-example) |
| 108 | +- [forwardRef/createRef](#forwardref-createref) |
| 109 | +- [Generic forwardRefs](#generic-forwardrefs) |
| 110 | +- [Option 1 - Wrapper component](#option-1---wrapper-component) |
| 111 | +- [Option 2 - Redeclare forwardRef](#option-2---redeclare-forwardref) |
| 112 | +- [More Info](#more-info) |
| 113 | +- [Portals](#portals) |
| 114 | +- [Error Boundaries](#error-boundaries) |
| 115 | +- [Option 1: Using react-error-boundary](#option-1--using-react-error-boundary) |
| 116 | +- [Options 2: Writing your custom error boundary component](#options-2--writing-your-custom-error-boundary-component) |
| 117 | +- [Concurrent React/React Suspense](#concurrent-react-react-suspense) |
| 118 | +- [Troubleshooting Handbook: Types](#troubleshooting-handbook--types) |
152 | 119 | <!--START-SECTION:types-toc-->
|
153 | 120 | - [Union Types and Type Guarding](#union-types-and-type-guarding)
|
154 | 121 | - [Optional Types](#optional-types)
|
|
169 | 136 | - [Frequent Known Problems with TypeScript](#frequent-known-problems-with-typescript)
|
170 | 137 | - [TypeScript doesn't narrow after an object element null check](#typescript-doesnt-narrow-after-an-object-element-null-check)
|
171 | 138 | - [TypeScript doesn't let you restrict the type of children](#typescript-doesnt-let-you-restrict-the-type-of-children)<!--END-SECTION:types-toc-->
|
172 |
| -- [Troubleshooting Handbook: Operators](#troubleshooting-handbook-operators) |
173 |
| -- [Troubleshooting Handbook: Utilties](#troubleshooting-handbook-utilities) |
174 |
| -- [Troubleshooting Handbook: tsconfig.json](#troubleshooting-handbook-tsconfigjson) |
175 |
| -- [Troubleshooting Handbook: Bugs in official typings](#troubleshooting-handbook-bugs-in-official-typings) |
176 |
| -- [Recommended React + TypeScript codebases to learn from](#recommended-react--typescript-codebases-to-learn-from) |
| 139 | +- [Troubleshooting Handbook: Operators](#troubleshooting-handbook--operators) |
| 140 | +- [Troubleshooting Handbook: Utilities](#troubleshooting-handbook--utilities) |
| 141 | +- [Troubleshooting Handbook: tsconfig.json](#troubleshooting-handbook--tsconfigjson) |
| 142 | +- [Troubleshooting Handbook: Fixing bugs in official typings](#troubleshooting-handbook--fixing-bugs-in-official-typings) |
| 143 | +- [Troubleshooting Handbook: Globals, Images and other non-TS files](#troubleshooting-handbook--globals--images-and-other-non-ts-files) |
177 | 144 | - [Editor Tooling and Integration](#editor-tooling-and-integration)
|
178 | 145 | - [Linting](#linting)
|
179 |
| -- [Other React + TypeScript resources](#other-react--typescript-resources) |
180 |
| -- [Recommended React + TypeScript talks](#recommended-react--typescript-talks) |
| 146 | +- [Other React + TypeScript resources](#other-react---typescript-resources) |
| 147 | +- [Recommended React + TypeScript talks](#recommended-react---typescript-talks) |
181 | 148 | - [Time to Really Learn TypeScript](#time-to-really-learn-typescript)
|
182 | 149 | - [Example App](#example-app)
|
183 |
| -- [My question isn't answered here!](#my-question-isnt-answered-here) |
184 |
| - </details> |
| 150 | + |
| 151 | + </details> |
185 | 152 |
|
186 | 153 | <!--START-SECTION:setup-->
|
187 | 154 |
|
|
0 commit comments