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: docs/tutorials/typescript.md
+33-40Lines changed: 33 additions & 40 deletions
Original file line number
Diff line number
Diff line change
@@ -7,39 +7,29 @@ hide_title: true
7
7
8
8
9
9
10
-
# React Redux TypeScript Quick Start
10
+
# Angular Redux TypeScript Quick Start
11
11
12
12
:::tip What You'll Learn
13
13
14
-
- How to set up and use Redux Toolkit and React Redux with TypeScript
14
+
- How to set up and use Redux Toolkit and Angular Redux with TypeScript
15
15
16
16
:::
17
17
18
18
:::info Prerequisites
19
19
20
-
- Knowledge of React [Hooks](https://react.dev/reference/react#)
20
+
- Knowledge of Angular [Signals](https://angular.dev/guide/signals)
21
21
- Understanding of [Redux terms and concepts](https://redux.js.org/tutorials/fundamentals/part-2-concepts-data-flow)
22
22
- Understanding of TypeScript syntax and concepts
23
23
24
24
:::
25
25
26
26
## Introduction
27
27
28
-
Welcome to the React Redux TypeScript Quick Start tutorial! **This tutorial will briefly show how to use TypeScript with Redux Toolkit and React-Redux**.
28
+
Welcome to the Angular Redux TypeScript Quick Start tutorial! **This tutorial will briefly show how to use TypeScript with Redux Toolkit and Angular-Redux**.
29
29
30
-
This page focuses on just how to set up the TypeScript aspects. For explanations of what Redux is, how it works, and full examples of how to use Redux, see [the Redux core docs tutorials](https://redux.js.org/tutorials/index).
30
+
This page focuses on just how to set up the TypeScript aspects. For explanations of what Redux is, how it works, and full examples of how to use Redux, see [the Redux core docs tutorials](https://redux.js.org/tutorials/index).
31
31
32
-
[React Redux](https://react-redux.js.org) is also written in TypeScript as of version 8, and also includes its own type definitions.
33
-
34
-
The [Redux+TS template for Create-React-App](https://github.com/reduxjs/cra-template-redux-typescript) comes with a working example of these patterns already configured.
35
-
36
-
:::info
37
-
38
-
The recently updated `@types/react@18` major version has changed component definitions to remove having `children` as a prop by default. This causes errors if you have multiple copies of `@types/react` in your project. To fix this, tell your package manager to resolve `@types/react` to a single version. Details:
[Angular Redux](/) is also written in TypeScript, and also includes its own type definitions.
43
33
44
34
## Project Setup
45
35
@@ -69,23 +59,23 @@ export type AppDispatch = typeof store.dispatch
69
59
// highlight-end
70
60
```
71
61
72
-
### Define Typed Hooks
62
+
### Define Typed Injectables
73
63
74
-
While it's possible to import the `RootState` and `AppDispatch` types into each component, it's **better to create typed versions of the `useDispatch` and `useSelector` hooks for usage in your application**. This is important for a couple reasons:
64
+
While it's possible to import the `RootState` and `AppDispatch` types into each component, it's **better to create typed versions of the `injectDispatch` and `injectSelector` injectables for usage in your application**. This is important for a couple reasons:
75
65
76
-
- For `useSelector`, it saves you the need to type `(state:RootState)` every time
77
-
- For `useDispatch`, the default `Dispatch` type does not know about thunks. In order to correctly dispatch thunks, you need to use the specific customized `AppDispatch` type from the store that includes the thunk middleware types, and use that with `useDispatch`. Adding a pre-typed `useDispatch` hook keeps you from forgetting to import `AppDispatch` where it's needed.
66
+
- For `injectSelector`, it saves you the need to type `(state:RootState)` every time
67
+
- For `injectDispatch`, the default `Dispatch` type does not know about thunks. In order to correctly dispatch thunks, you need to use the specific customized `AppDispatch` type from the store that includes the thunk middleware types, and use that with `injectDispatch`. Adding a pre-typed `injectDispatch` injectable keeps you from forgetting to import `AppDispatch` where it's needed.
78
68
79
-
Since these are actual variables, not types, it's important to define them in a separate file such as `app/hooks.ts`, not the store setup file. This allows you to import them into any component file that needs to use the hooks, and avoids potential circular import dependency issues.
69
+
Since these are actual variables, not types, it's important to define them in a separate file such as `app/injectables.ts`, not the store setup file. This allows you to import them into any component file that needs to use the injectables, and avoids potential circular import dependency issues.
See [the "Usage with TypeScript" page](../using-react-redux/usage-with-typescript.md) for extended details on how to use Redux Toolkit's APIs with TypeScript.
175
+
See [the "Usage with TypeScript" page](../using-angular-redux/usage-with-typescript.md) for extended details on how to use Redux Toolkit's APIs with TypeScript.
0 commit comments