Skip to content

Commit 38ec3b0

Browse files
Update dependencies (#817)
* Update dependencies * dependency upgrades * set node version * use node 20
1 parent 168469a commit 38ec3b0

21 files changed

Lines changed: 6505 additions & 5655 deletions

.husky/pre-commit

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
#!/bin/sh
2-
. "$(dirname "$0")/_/husky.sh"
3-
41
yarn pretty-quick --staged

.prettierrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"trailingComma": "es5"
3+
}

README.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ Some differences from the "normal function" version:
230230
- `React.FunctionComponent` is explicit about the return type, while the normal function version is implicit (or else needs additional annotation).
231231

232232
- It provides typechecking and autocomplete for static properties like `displayName`, `propTypes`, and `defaultProps`.
233-
234233
- Note that there are some known issues using `defaultProps` with `React.FunctionComponent`. See [this issue for details](https://github.com/typescript-cheatsheets/react/issues/87). We maintain a separate `defaultProps` section you can also look up.
235234

236235
- Before the [React 18 type updates](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/56210), `React.FunctionComponent` provided an implicit definition of `children` (see below), which was heavily debated and is one of the reasons [`React.FC` was removed from the Create React App TypeScript template](https://github.com/facebook/create-react-app/pull/8177).
@@ -362,7 +361,7 @@ In React >= 18, the function signature of `useCallback` changed to the following
362361
function useCallback<T extends Function>(callback: T, deps: DependencyList): T;
363362
```
364363

365-
Therefore, the following code will yield "`Parameter 'e' implicitly has an 'any' type.`" error in React >= 18, but not <17.
364+
Therefore, the following code will yield "`Parameter 'e' implicitly has an 'any' type.`" error in React >= 18, but not &lt;17.
366365

367366
```ts
368367
// @ts-expect-error Parameter 'e' implicitly has 'any' type.
@@ -646,7 +645,7 @@ export function useLoading() {
646645
};
647646
return [isLoading, load] as [
648647
boolean,
649-
(aPromise: Promise<any>) => Promise<any>
648+
(aPromise: Promise<any>) => Promise<any>,
650649
];
651650
}
652651
```
@@ -825,7 +824,7 @@ class Comp extends React.Component<Props, State> {
825824
```tsx
826825
class Comp extends React.Component<
827826
Props,
828-
ReturnType<typeof Comp["getDerivedStateFromProps"]>
827+
ReturnType<(typeof Comp)["getDerivedStateFromProps"]>
829828
> {
830829
static getDerivedStateFromProps(props: Props) {}
831830
}
@@ -1295,7 +1294,7 @@ class Comp extends React.Component<Props, State> {
12951294
```tsx
12961295
class Comp extends React.Component<
12971296
Props,
1298-
ReturnType<typeof Comp["getDerivedStateFromProps"]>
1297+
ReturnType<(typeof Comp)["getDerivedStateFromProps"]>
12991298
> {
13001299
static getDerivedStateFromProps(props: Props) {}
13011300
}
@@ -1383,10 +1382,10 @@ class App extends React.Component<Props, State> {
13831382
Instead of typing the arguments and return values with `React.FormEvent<>` and `void`, you may alternatively apply types to the event handler itself (_contributed by @TomasHubelbauer_):
13841383

13851384
```tsx
1386-
// typing on LEFT hand side of =
1387-
onChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
1388-
this.setState({text: e.currentTarget.value})
1389-
}
1385+
// typing on LEFT hand side of =
1386+
onChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
1387+
this.setState({ text: e.currentTarget.value });
1388+
};
13901389
```
13911390

13921391
<details>
@@ -1814,9 +1813,9 @@ If you need both generic support and proper forwardRef behavior with full type i
18141813
```tsx
18151814
// Add to your type definitions (e.g. in `index.d.ts` file)
18161815
interface ForwardRefWithGenerics extends React.FC<WithForwardRefProps<Option>> {
1817-
<T extends Option>(props: WithForwardRefProps<T>): ReturnType<
1818-
React.FC<WithForwardRefProps<T>>
1819-
>;
1816+
<T extends Option>(
1817+
props: WithForwardRefProps<T>
1818+
): ReturnType<React.FC<WithForwardRefProps<T>>>;
18201819
}
18211820

18221821
export const ClickableListWithForwardRef: ForwardRefWithGenerics =
@@ -2015,7 +2014,7 @@ export default ErrorBoundary;
20152014

20162015
#### Concurrent React/React Suspense
20172016

2018-
_Not written yet._ watch <https://github.com/sw-yx/fresh-async-react> for more on React Suspense and Time Slicing.
2017+
_Not written yet._ watch [https://github.com/sw-yx/fresh-async-react](https://github.com/sw-yx/fresh-async-react) for more on React Suspense and Time Slicing.
20192018

20202019
[Something to add? File an issue](https://github.com/typescript-cheatsheets/react/issues/new).
20212020

@@ -2929,9 +2928,9 @@ If you're looking for information on Prettier, check out the [Prettier](https://
29292928
29302929
### Other React + TypeScript resources
29312930
2932-
- me! <https://twitter.com/swyx>
2931+
- me! [https://twitter.com/swyx](https://twitter.com/swyx)
29332932
- https://www.freecodecamp.org/news/how-to-build-a-todo-app-with-react-typescript-nodejs-and-mongodb/
2934-
- <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**.
2933+
- [https://github.com/piotrwitek/react-redux-typescript-guide](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**.
29352934
- [10 Bad TypeScript Habits](https://startup-cto.net/10-bad-typescript-habits-to-break-this-year/):
29362935
1. not using `"strict": true`
29372936
2. using `||` for default values when we have `??`

docs/advanced/misc-concerns.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default Object.assign(Form, { Input: Input });
8383

8484
I do like [Docz](https://docz.site/) which takes basically [1 line of config](https://www.docz.site/documentation/project-configuration#typescript) to accept TypeScript. However it is newer and has a few more rough edges (many breaking changes since it is still < v1.0)
8585

86-
For developing with Storybook, read the docs I wrote over here: <https://storybook.js.org/configurations/typescript-config/>. This includes automatic proptype documentation generation, which is awesome :)
86+
For developing with Storybook, read the docs I wrote over here: [https://storybook.js.org/configurations/typescript-config/](https://storybook.js.org/configurations/typescript-config/). This includes automatic proptype documentation generation, which is awesome :)
8787

8888
[Something to add? File an issue](https://github.com/typescript-cheatsheets/react/issues/new).
8989

@@ -99,9 +99,9 @@ You should check out large projects that are migrating from flow to pick up conc
9999

100100
Useful libraries:
101101

102-
- <https://github.com/bcherny/flow-to-typescript>
103-
- <https://github.com/Khan/flow-to-ts>
104-
- <https://github.com/piotrwitek/utility-types>
102+
- [https://github.com/bcherny/flow-to-typescript](https://github.com/bcherny/flow-to-typescript)
103+
- [https://github.com/Khan/flow-to-ts](https://github.com/Khan/flow-to-ts)
104+
- [https://github.com/piotrwitek/utility-types](https://github.com/piotrwitek/utility-types)
105105

106106
If you have specific advice in this area, please file a PR!
107107

docs/advanced/patterns_by_usecase.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,12 @@ Example:
129129

130130
```tsx
131131
// ReactUtilityTypes.d.ts
132-
declare type $ElementProps<T> = T extends React.ComponentType<infer Props>
133-
? Props extends object
134-
? Props
135-
: never
136-
: never;
132+
declare type $ElementProps<T> =
133+
T extends React.ComponentType<infer Props>
134+
? Props extends object
135+
? Props
136+
: never
137+
: never;
137138
```
138139

139140
Usage:
@@ -142,7 +143,7 @@ Usage:
142143
import * as Recompose from "recompose";
143144
export const defaultProps = <
144145
C extends React.ComponentType,
145-
D extends Partial<$ElementProps<C>>
146+
D extends Partial<$ElementProps<C>>,
146147
>(
147148
defaults: D,
148149
Component: C
@@ -635,8 +636,7 @@ function App() {
635636
}
636637
```
637638

638-
<a href="https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcA5FDvmQNwBQdMAnmFnAArFjoC8dccAD5wA3vwETgqAIJQoyJgC44MKAFcs9CRIBuyADYblqVcAB2AcwDaAXRpxxAgL7jhY7QKmz5SuAQOomo66BkZwJlDmFloSTvS4EGYmcAAacDxwABRgypwQ3ACU6QB8ouKUMGpQZphUMAB0aoEAslggEJnBmUU8pZ0ecAA8ACbAOsXB2nqGWJmoBYqTEiJg9V5yCnAAZFtwq9Ma9QBWEOaZZAA0ZAUuAwIiAISr6z7bu-uhWLcegwD0o+NggULsErM8ZBsmBc9vUDlgbNDfr84AAVFhYVC4SJgeDINQwEjIGDAXAGfRMOAgIm4AAWGJUdLgCTkGMgZlGljgcJU6PEBXocToBDUZnwwEScGkYDA3TKAgqVRq-QkIzGTP0aFQADlkCAsDwAERSsAGiYDQZpF4KHgifz6QJOLmfG1kAgQCBkR2-M0-S0Qnw21QaR1wm1WV3uy7kABGyCgUbIsYAXmQbF6fQI-gCffy6E4gA"><i>See this in TS Playground</i>
639-
</a>
639+
[_See this in TS Playground_](https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcA5FDvmQNwBQdMAnmFnAArFjoC8dccAD5wA3vwETgqAIJQoyJgC44MKAFcs9CRIBuyADYblqVcAB2AcwDaAXRpxxAgL7jhY7QKmz5SuAQOomo66BkZwJlDmFloSTvS4EGYmcAAacDxwABRgypwQ3ACU6QB8ouKUMGpQZphUMAB0aoEAslggEJnBmUU8pZ0ecAA8ACbAOsXB2nqGWJmoBYqTEiJg9V5yCnAAZFtwq9Ma9QBWEOaZZAA0ZAUuAwIiAISr6z7bu-uhWLcegwD0o+NggULsErM8ZBsmBc9vUDlgbNDfr84AAVFhYVC4SJgeDINQwEjIGDAXAGfRMOAgIm4AAWGJUdLgCTkGMgZlGljgcJU6PEBXocToBDUZnwwEScGkYDA3TKAgqVRq-QkIzGTP0aFQADlkCAsDwAERSsAGiYDQZpF4KHgifz6QJOLmfG1kAgQCBkR2-M0-S0Qnw21QaR1wm1WV3uy7kABGyCgUbIsYAXmQbF6fQI-gCffy6E4gA)
640640

641641
In the above example, based on the `isArray` union member, the type of the `value` hook dependency changes.
642642

docs/advanced/patterns_by_version.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,6 @@ You can [convert these in bulk](https://github.com/microsoft/TypeScript/pull/374
423423
[[Release Notes](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html) | [Blog Post](https://devblogs.microsoft.com/typescript/announcing-typescript-4-0/)]
424424

425425
- [Variadic Tuple Types](https://devblogs.microsoft.com/typescript/announcing-typescript-4-0-beta/#variadic-tuple-types)
426-
427426
- useful for [simplified Reducer-like State](https://www.reddit.com/r/reactjs/comments/hu0ytg/simplified_reducerlike_state_using_typescript_40/)
428427

429428
- [Custom JSX Factories](https://devblogs.microsoft.com/typescript/announcing-typescript-4-0/#custom-jsx-factories)

docs/basic/getting-started/class-components.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class Comp extends React.Component<Props, State> {
132132
```tsx
133133
class Comp extends React.Component<
134134
Props,
135-
ReturnType<typeof Comp["getDerivedStateFromProps"]>
135+
ReturnType<(typeof Comp)["getDerivedStateFromProps"]>
136136
> {
137137
static getDerivedStateFromProps(props: Props) {}
138138
}

docs/basic/getting-started/concurrent.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ id: concurrent
33
title: Concurrent React/React Suspense
44
---
55

6-
_Not written yet._ watch <https://github.com/sw-yx/fresh-async-react> for more on React Suspense and Time Slicing.
6+
_Not written yet._ watch [https://github.com/sw-yx/fresh-async-react](https://github.com/sw-yx/fresh-async-react) for more on React Suspense and Time Slicing.
77

88
[Something to add? File an issue](https://github.com/typescript-cheatsheets/react/issues/new).

docs/basic/getting-started/forms-and-events.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ class App extends React.Component<Props, State> {
4545
Instead of typing the arguments and return values with `React.FormEvent<>` and `void`, you may alternatively apply types to the event handler itself (_contributed by @TomasHubelbauer_):
4646

4747
```tsx
48-
// typing on LEFT hand side of =
49-
onChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
50-
this.setState({text: e.currentTarget.value})
51-
}
48+
// typing on LEFT hand side of =
49+
onChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
50+
this.setState({ text: e.currentTarget.value });
51+
};
5252
```
5353

5454
<details>

docs/basic/getting-started/forward-create-ref.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ If you need both generic support and proper forwardRef behavior with full type i
198198
```tsx
199199
// Add to your type definitions (e.g. in `index.d.ts` file)
200200
interface ForwardRefWithGenerics extends React.FC<WithForwardRefProps<Option>> {
201-
<T extends Option>(props: WithForwardRefProps<T>): ReturnType<
202-
React.FC<WithForwardRefProps<T>>
203-
>;
201+
<T extends Option>(
202+
props: WithForwardRefProps<T>
203+
): ReturnType<React.FC<WithForwardRefProps<T>>>;
204204
}
205205

206206
export const ClickableListWithForwardRef: ForwardRefWithGenerics =

0 commit comments

Comments
 (0)