質問編集履歴
7
コード修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -162,8 +162,10 @@
|
|
162
162
|
|
163
163
|
- rootSlice.ts
|
164
164
|
```
|
165
|
-
import { createSlice } from '@reduxjs/toolkit'
|
166
|
-
|
165
|
+
type Addresses = {
|
166
|
+
Name: string
|
167
|
+
Address: string
|
168
|
+
}
|
167
169
|
|
168
170
|
type State = {
|
169
171
|
addressbook: Addresses[]
|
@@ -182,10 +184,9 @@
|
|
182
184
|
name: 'addressbook',
|
183
185
|
initialState,
|
184
186
|
reducers: {
|
185
|
-
setName: (state, action) => { state.Name = action.payload },
|
186
187
|
setAddressBook: (state, action) => { state.addressbook = action.payload },
|
187
188
|
addAddresses: (state, action) => {
|
188
|
-
state.
|
189
|
+
state.addressbook.push({Name: "", Address: ""})
|
189
190
|
}
|
190
191
|
}
|
191
192
|
})
|
@@ -193,9 +194,11 @@
|
|
193
194
|
export const reducer = rootSlice.reducer;
|
194
195
|
|
195
196
|
export const {
|
196
|
-
|
197
|
+
setAddressBook,
|
197
198
|
addAddresses
|
198
199
|
} = rootSlice.actions
|
200
|
+
|
201
|
+
export default rootSlice
|
199
202
|
```
|
200
203
|
|
201
204
|
- rootReducer.ts
|
6
コード追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -217,4 +217,33 @@
|
|
217
217
|
Name: string
|
218
218
|
Address: string
|
219
219
|
}
|
220
|
+
```
|
221
|
+
|
222
|
+
- tsconfig.json
|
223
|
+
```
|
224
|
+
{
|
225
|
+
"compilerOptions": {
|
226
|
+
"target": "es5",
|
227
|
+
"lib": [
|
228
|
+
"dom",
|
229
|
+
"dom.iterable",
|
230
|
+
"esnext"
|
231
|
+
],
|
232
|
+
"allowJs": true,
|
233
|
+
"skipLibCheck": true,
|
234
|
+
"esModuleInterop": true,
|
235
|
+
"allowSyntheticDefaultImports": true,
|
236
|
+
"strict": true,
|
237
|
+
"forceConsistentCasingInFileNames": true,
|
238
|
+
"module": "esnext",
|
239
|
+
"moduleResolution": "node",
|
240
|
+
"resolveJsonModule": true,
|
241
|
+
"isolatedModules": true,
|
242
|
+
"noEmit": true,
|
243
|
+
"jsx": "react"
|
244
|
+
},
|
245
|
+
"include": [
|
246
|
+
"src"
|
247
|
+
]
|
248
|
+
}
|
220
249
|
```
|
5
タグ修正
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
4
文言修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,11 +4,23 @@
|
|
4
4
|
Address: string
|
5
5
|
}
|
6
6
|
のようなhash を配列としてもたせたデータをUI上から入力、出力するような
|
7
|
-
画面を作成中ですが、
|
7
|
+
画面を作成中ですが、以下のエラーでうまく動かない状態です。。。
|
8
8
|
|
9
|
+
```
|
10
|
+
TypeScript error in App.tsx(13,21):
|
11
|
+
Parameter 'data' implicitly has an 'any' type. TS7006
|
12
|
+
```
|
13
|
+
|
14
|
+
App.tsx 内の
|
15
|
+
```
|
16
|
+
const onSubmit = (data) => {
|
17
|
+
dispatch(setAddresses(data.addressbook))
|
18
|
+
}
|
19
|
+
```
|
9
|
-
"data" の型が指定されていないことでのエラーというのは
|
20
|
+
にて"data" の型が指定されていないことでのエラーというのは
|
10
21
|
わかっているのですが、本件であればどのように
|
11
22
|
指定すればよいのかがわからず・・・。
|
23
|
+
※いくつかの参考文献をもとにこのように書いてしまってます・・・
|
12
24
|
|
13
25
|
以下のようなコードですが原因や修正点など
|
14
26
|
わかる方いらっしゃいましたらご教授ください。。。
|
3
文言修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
Name: string
|
4
4
|
Address: string
|
5
5
|
}
|
6
|
-
のようなhash を配列
|
6
|
+
のようなhash を配列としてもたせたデータをUI上から入力、出力するような
|
7
7
|
画面を作成中ですが、掲題のエラーでうまく動かない状態です。。。
|
8
8
|
|
9
9
|
"data" の型が指定されていないことでのエラーというのは
|
2
コード修正、新コード追加
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
エラー "
|
1
|
+
エラー "Parameter 'data' implicitly has an 'any' type.'." が出力されてしまう
|
body
CHANGED
@@ -6,6 +6,10 @@
|
|
6
6
|
のようなhash を配列にもつデータをUI上から入力、出力するような
|
7
7
|
画面を作成中ですが、掲題のエラーでうまく動かない状態です。。。
|
8
8
|
|
9
|
+
"data" の型が指定されていないことでのエラーというのは
|
10
|
+
わかっているのですが、本件であればどのように
|
11
|
+
指定すればよいのかがわからず・・・。
|
12
|
+
|
9
13
|
以下のようなコードですが原因や修正点など
|
10
14
|
わかる方いらっしゃいましたらご教授ください。。。
|
11
15
|
|
@@ -38,11 +42,12 @@
|
|
38
42
|
import { useDispatch, useSelector } from "react-redux"
|
39
43
|
import { useForm } from 'react-hook-form'
|
40
44
|
import { setAddresses } from './rootSlice'
|
45
|
+
import { RootState } from './rootReducer'
|
41
46
|
import './common.css'
|
42
47
|
|
43
48
|
const App = () => {
|
44
49
|
const dispatch = useDispatch();
|
45
|
-
const addressbook = useSelector(state => state.addressbook)
|
50
|
+
const addressbook = useSelector((state: RootState) => state.addressbook)
|
46
51
|
const { register, handleSubmit } = useForm();
|
47
52
|
|
48
53
|
const onSubmit = (data) => {
|
@@ -181,6 +186,19 @@
|
|
181
186
|
} = rootSlice.actions
|
182
187
|
```
|
183
188
|
|
189
|
+
- rootReducer.ts
|
190
|
+
```
|
191
|
+
import { combineReducers } from '@reduxjs/toolkit'
|
192
|
+
import rootSlice from './rootSlice'
|
193
|
+
|
194
|
+
export const rootReducer = combineReducers({
|
195
|
+
addressbook: rootSlice.reducer
|
196
|
+
})
|
197
|
+
|
198
|
+
export type RootState = ReturnType<typeof rootReducer>
|
199
|
+
export default rootReducer
|
200
|
+
```
|
201
|
+
|
184
202
|
- Types.ts
|
185
203
|
```
|
186
204
|
export type Addresses = {
|
1
タイトル修正
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
Property 'XXX' does not exist on type 'DefaultRootState'.
|
1
|
+
エラー "Property 'XXX' does not exist on type 'DefaultRootState'." が出力されてしまう
|
body
CHANGED
File without changes
|