質問編集履歴

7

コード修正

2020/08/06 11:01

投稿

07290729
07290729

スコア15

test CHANGED
File without changes
test CHANGED
@@ -326,9 +326,13 @@
326
326
 
327
327
  ```
328
328
 
329
- import { createSlice } from '@reduxjs/toolkit'
330
-
331
- import { AddressBook } from './Types'
329
+ type Addresses = {
330
+
331
+ Name: string
332
+
333
+ Address: string
334
+
335
+ }
332
336
 
333
337
 
334
338
 
@@ -366,13 +370,11 @@
366
370
 
367
371
  reducers: {
368
372
 
369
- setName: (state, action) => { state.Name = action.payload },
370
-
371
373
  setAddressBook: (state, action) => { state.addressbook = action.payload },
372
374
 
373
375
  addAddresses: (state, action) => {
374
376
 
375
- state.Addresses.push(`address${state.Addresses.length}`)
377
+ state.addressbook.push({Name: "", Address: ""})
376
378
 
377
379
  }
378
380
 
@@ -388,12 +390,16 @@
388
390
 
389
391
  export const {
390
392
 
391
- setAddresses,
393
+ setAddressBook,
392
394
 
393
395
  addAddresses
394
396
 
395
397
  } = rootSlice.actions
396
398
 
399
+
400
+
401
+ export default rootSlice
402
+
397
403
  ```
398
404
 
399
405
 

6

コード追加

2020/08/06 11:01

投稿

07290729
07290729

スコア15

test CHANGED
File without changes
test CHANGED
@@ -437,3 +437,61 @@
437
437
  }
438
438
 
439
439
  ```
440
+
441
+
442
+
443
+ - tsconfig.json
444
+
445
+ ```
446
+
447
+ {
448
+
449
+ "compilerOptions": {
450
+
451
+ "target": "es5",
452
+
453
+ "lib": [
454
+
455
+ "dom",
456
+
457
+ "dom.iterable",
458
+
459
+ "esnext"
460
+
461
+ ],
462
+
463
+ "allowJs": true,
464
+
465
+ "skipLibCheck": true,
466
+
467
+ "esModuleInterop": true,
468
+
469
+ "allowSyntheticDefaultImports": true,
470
+
471
+ "strict": true,
472
+
473
+ "forceConsistentCasingInFileNames": true,
474
+
475
+ "module": "esnext",
476
+
477
+ "moduleResolution": "node",
478
+
479
+ "resolveJsonModule": true,
480
+
481
+ "isolatedModules": true,
482
+
483
+ "noEmit": true,
484
+
485
+ "jsx": "react"
486
+
487
+ },
488
+
489
+ "include": [
490
+
491
+ "src"
492
+
493
+ ]
494
+
495
+ }
496
+
497
+ ```

5

タグ修正

2020/08/06 10:59

投稿

07290729
07290729

スコア15

test CHANGED
File without changes
test CHANGED
File without changes

4

文言修正

2020/08/03 18:28

投稿

07290729
07290729

スコア15

test CHANGED
File without changes
test CHANGED
@@ -10,16 +10,40 @@
10
10
 
11
11
  のようなhash を配列としてもたせたデータをUI上から入力、出力するような
12
12
 
13
- 画面を作成中ですが、掲題のエラーでうまく動かない状態です。。。
13
+ 画面を作成中ですが、以下のエラーでうまく動かない状態です。。。
14
+
15
+
16
+
14
-
17
+ ```
18
+
15
-
19
+ TypeScript error in App.tsx(13,21):
20
+
16
-
21
+ Parameter 'data' implicitly has an 'any' type. TS7006
22
+
23
+ ```
24
+
25
+
26
+
27
+ App.tsx 内の
28
+
29
+ ```
30
+
31
+ const onSubmit = (data) => {
32
+
33
+ dispatch(setAddresses(data.addressbook))
34
+
35
+ }
36
+
37
+ ```
38
+
17
- "data" の型が指定されていないことでのエラーというのは
39
+ にて"data" の型が指定されていないことでのエラーというのは
18
40
 
19
41
  わかっているのですが、本件であればどのように
20
42
 
21
43
  指定すればよいのかがわからず・・・。
22
44
 
45
+ ※いくつかの参考文献をもとにこのように書いてしまってます・・・
46
+
23
47
 
24
48
 
25
49
  以下のようなコードですが原因や修正点など

3

文言修正

2020/08/03 12:24

投稿

07290729
07290729

スコア15

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  }
10
10
 
11
- のようなhash を配列データをUI上から入力、出力するような
11
+ のようなhash を配列としてたせたデータをUI上から入力、出力するような
12
12
 
13
13
  画面を作成中ですが、掲題のエラーでうまく動かない状態です。。。
14
14
 

2

コード修正、新コード追加

2020/08/03 12:02

投稿

07290729
07290729

スコア15

test CHANGED
@@ -1 +1 @@
1
- エラー "Property 'XXX' does not exist on type 'DefaultRootState'." が出力されてしまう
1
+ エラー "Parameter 'data' implicitly has an 'any' type.'." が出力されてしまう
test CHANGED
@@ -14,6 +14,14 @@
14
14
 
15
15
 
16
16
 
17
+ "data" の型が指定されていないことでのエラーというのは
18
+
19
+ わかっているのですが、本件であればどのように
20
+
21
+ 指定すればよいのかがわからず・・・。
22
+
23
+
24
+
17
25
  以下のようなコードですが原因や修正点など
18
26
 
19
27
  わかる方いらっしゃいましたらご教授ください。。。
@@ -78,6 +86,8 @@
78
86
 
79
87
  import { setAddresses } from './rootSlice'
80
88
 
89
+ import { RootState } from './rootReducer'
90
+
81
91
  import './common.css'
82
92
 
83
93
 
@@ -86,7 +96,7 @@
86
96
 
87
97
  const dispatch = useDispatch();
88
98
 
89
- const addressbook = useSelector(state => state.addressbook)
99
+ const addressbook = useSelector((state: RootState) => state.addressbook)
90
100
 
91
101
  const { register, handleSubmit } = useForm();
92
102
 
@@ -364,6 +374,32 @@
364
374
 
365
375
 
366
376
 
377
+ - rootReducer.ts
378
+
379
+ ```
380
+
381
+ import { combineReducers } from '@reduxjs/toolkit'
382
+
383
+ import rootSlice from './rootSlice'
384
+
385
+
386
+
387
+ export const rootReducer = combineReducers({
388
+
389
+ addressbook: rootSlice.reducer
390
+
391
+ })
392
+
393
+
394
+
395
+ export type RootState = ReturnType<typeof rootReducer>
396
+
397
+ export default rootReducer
398
+
399
+ ```
400
+
401
+
402
+
367
403
  - Types.ts
368
404
 
369
405
  ```

1

タイトル修正

2020/08/03 12:02

投稿

07290729
07290729

スコア15

test CHANGED
@@ -1 +1 @@
1
- Property 'XXX' does not exist on type 'DefaultRootState'.
1
+ エラー "Property 'XXX' does not exist on type 'DefaultRootState'." が出力されてしまう
test CHANGED
File without changes