なつねこメモ

主にプログラミング関連のメモ帳 ♪(✿╹ヮ╹)ノ

書いてあるコードは自己責任でご自由にどうぞ。記事本文の無断転載は禁止です。

2016/01/28

TypeScript で redux-thunk を使うとき

カテゴリー:

ぐぐったら、すでにあったけど、私はこの方法で解決したぜ!というメモで。

TypeScript で redux-thunk を使おうとすると、エラーが出ます。
具体的には、こんな時にエラーが出ます。

src/store/configureStore.ts
/// <reference path="../typings/tsd.d.ts" />
 
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import rootReducers from '../reducers/index';
 
const createStoreWithMiddleware = applyMiddleware(
  thunk
)(createStore);
 
export default function configureStore(initialState) {
  return createStoreWithMiddleware(rootReducers, initialState);
}

直し方は、 import 部分を、下のように修正します。

import * as thunk from "redux-thunk";

一応、 Issue も上がっているようです。

redux-thunk and TypeScript 1.6 · Issue #6231 · DefinitelyTyped/DefinitelyTyped · GitHub

Copyright (c) 2015 - 2023 Natsuneko <me@natsuneko.cat>