LoginSignup
0

More than 3 years have passed since last update.

TypeScript + Reduxの型のimportでつまずいた件

Last updated at Posted at 2019-08-13

TypeScriptでReduxを書いていて、Actionの型をreduxからimportしようとしたとき下記のエラーが出て困ったので、(とても簡単ですが)解決法をメモしておきます。


import { Action } from 'redux'

と書くと、「"Action"はreduxのexportメンバーにないよ!」って怒られました。


TS2305: Module '"/node_modules/redux/es/redux"' has no exported member 'Action'.

下記のように記述するとエラーは消えたのですが、


import { Action } from 'redux/index.d.ts'

こんな書き方あまり見たことないし、ちょっと気持ち悪かったので数時間調べて最終的にstackoverflowで聞いたところ、

Redux provides it's own type definitions, so you don't need to install them from Definitely Typed. If you uninstall @types/redux, TypeScript should use those provided by the redux package, and your import will work.

[和訳] Redux自体が型定義を提供しているので、TypeScript型定義ファイル(dts)をインストールしなくていいよ。@types/reduxをアンインストールすればTypeScriptはReduxの型定義を読みに言ってエラーは消えるよ。

とのことで、早速試したところ動きました。@types/reduxはdeprecatedになっていたみたいですね。

参考: https://stackoverflow.com/questions/57470757/typescript-cannot-find-imported-type-action

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0