Typescript cannot find imported type Action

I am working on my typescript + redux project and trying to import type Action from redux as below.

import { Action } from 'redux'

It shows an error which says,

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

However, I see there's the type declaration in redux/index.d.ts and it works when I write like this,

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

According to this example, https://redux.js.org/recipes/usage-with-typescript#usage-with-redux-thunk, it seems to work with import { Action } from 'redux', but not in my case. Is there any additional config for this?

I have already installed the versions in my environment.

  • "redux": "^4.0.4"
  • "@types/redux": "^3.6.0"

Here is my tsconfig.json

{
  "compilerOptions": {
    "baseUrl": ".",
    "outDir": "./dist/",
    "sourceMap": true,
    "noImplicitAny": true,
    "skipLibCheck": true,
    "module": "es2015",
    "target": "es5",
    "jsx": "react",
    "strictNullChecks": true,
    "allowJs": true,
    "declaration": false,
    "allowSyntheticDefaultImports": true,
    "moduleResolution": "node",
    "lib": [
      "dom",
      "es2015",
      "es5",
      "es6"
    ]
  }
}

Thanks!

1 answer

  • answered 2019-08-13 04:40 mguida

    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.

    The @types/redux package has been deprecated.