現在、以下のテンプレートを参考にNuxt-Typescriptにて
実装を行っています。
https://github.com/nuxt-community/typescript-template
そこでテンプレートに最初から配置されていた\myProject\store\index.tsを以下のように
修正するとbuild時にエラーが発生します。
仕様としては各記事のリンクを押した際に各記事のidを渡して内容を取得し表示しようと思っており
画面でボタンが押された際に、xxxx.vue内にて
js
1this.$store.dispatch('getArticle', {payload: { id:"" }})
のような形でstoreのactionを呼び出したいと思っています。
困っているのは以下の該当メソッドのgetArticleの引数に何を設定したら良いか理解できていません。
エラーの内容から型の不一致でないかと考えているのですが
どこで定義されているどの型定義に合わせるべきかがわかりません
どなたか引数の設定内容(設定方法)、についてご教示頂けないでしょうか。
■index.ts
typescript
1import { RootState, Article } from "../types"; 2import { MutationTree, ActionTree,ActionContext } from "vuex"; 3import axios from 'axios' 4// export let state:RootState; 5export const state = (): RootState => ({ 6 article:null, 7 articles: [] 8}) 9 10export const mutations: MutationTree<RootState> = { 11 setArticle(state: RootState, article: Article): void { 12 state.article = article 13 } 14} 15 16export const actions: ActionTree<RootState, any> = { 17 18 async getArticle({ commit }, { payload }:any){ 19 let article:Article 20 article.id = payload.id 21 commit("setArticle", payload.id) 22 }, 23}
■state.ts
typescript
1import { Article } from "../types"; 2 3export interface RootState { 4 article:Article, 5 articles:Article[] 6}
■build時出力ログ
log
1[tsl] ERROR in C:Users\myProjec\store\index.ts(25,111) 2 TS2322: Type '0' is not assignable to type '{ label: number; sent: () => any; trys: never[]; ops: never[]; }'. 3 friendly-errors 11:49:13 4 ERROR in C:Users\myProjec\store\index.ts 5[tsl] ERROR in C:UsersmyProjec\store\index.ts(28,75) 6 TS2345: Argument of type 'any' is not assignable to parameter of type 'never'. 7 friendly-errors 11:49:13
■package.json 抜粋
json
1"dependencies": { 2 "@nuxtjs/axios": "^5.3.6", 3 "cross-env": "^5.2.0", 4 "micro": "^9.3.3", 5 "micro-route": "^2.5.0", 6 "nuxt": "^2.3.4", 7 "nuxt-class-component": "^1.2.1", 8 "nuxt-property-decorator": "1.3.1", 9 "vue-property-decorator": "^7.3.0", 10 "vuex-class": "0.3.1" 11 }, 12 "devDependencies": { 13 "nodemon": "^1.18.9", 14 "ts-loader": "5.3.3", 15 "typescript": "3.2.4" 16 }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/25 03:18 編集
2019/04/25 04:10
2019/04/25 07:37 編集
2019/04/25 10:17 編集
2019/04/26 00:58
2019/04/27 04:47