打字稿找不到redux

拉尔夫:

我收到以下错误:

node_modules/@types/react-redux/index.d.ts(8,24): error TS2307: Cannot find module 'redux'.

尽管同时安装了react-reduxreduxpackage.json):

"dependencies": {
    "react": "15.4.2",
    "react-native": "0.42.3",
    "react-redux": "^5.0.3",
    "redux": "^3.6.0"
},
"devDependencies": {
    "@types/react": "^15.0.18",
    "@types/react-native": "^0.42.9",
    "@types/react-redux": "^4.4.38",
    "@types/redux": "^3.6.0",
    "babel-jest": "19.0.0",
    "babel-preset-react-native": "1.9.1",
    "jest": "19.0.2",
    "react-test-renderer": "15.4.2",
    "tslint": "^4.5.1",
    "typescript": "^2.2.1"
},

README.md文件@types/redux说:

This is a stub types definition for Redux (https://github.com/reactjs/redux).
Redux provides its own type definitions, so you don't need @types/redux installed!

但是卸载@types/redux软件包没有什么区别。

有任何想法吗?

更新

我以为通过将an添加index.d.ts@types/redux目录(仅包含export * from ../../redux/index)中,可以解决问题,但没有任何乐趣。

这是我的tsconfig.json

{
    "compilerOptions": {
        "target": "es2015",
        "module": "es2015",
        "jsx": "react",
        "outDir": "build",
        "rootDir": "src",
        "allowSyntheticDefaultImports": true,
        "noImplicitAny": true,
        "experimentalDecorators": true,
        "preserveConstEnums": true,
        "allowJs": true,
        "sourceMap": true
    },
    "filesGlob": [
        "src/**/*.ts",
        "src/**/*.tsx"
    ],
    "exclude": [
        "__tests__",
        "index.android.js",
        "index.ios.js",
        "build",
        "node_modules"
    ],
    "compileOnSave": false
}

并且我绝对@types/redux从中删除了该目录node_modules我(显然)正在运行TypeScript 2.2.1。

更新2

使用代码redux

import { combineReducers } from "redux"

export default combineReducers({})

请注意,在之后添加分号"redux"无济于事。

安德鲁·辛纳(Andrew Sinner):

我在本机项目中遇到了同样的问题。此修复程序对我有用:

您必须在编译器选项中添加“ moduleResolution”:“ node”,以包括链接在package.json文件中的类型定义。

此处的文档https://www.typescriptlang.org/docs/handbook/module-resolution.html

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章