Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs react redux打字文件中的TypeScript错误_Reactjs_Typescript_Redux_React Redux_Typescript Typings - Fatal编程技术网

Reactjs react redux打字文件中的TypeScript错误

Reactjs react redux打字文件中的TypeScript错误,reactjs,typescript,redux,react-redux,typescript-typings,Reactjs,Typescript,Redux,React Redux,Typescript Typings,TypeScript编译器在react-redux typings文件中报告错误,尽管我已将typings目录排除在tsconfig中 打字稿版本:1.8.10 下面是我得到的错误 /home/me/dev/proj/typings/main/ambient/react redux/index.d.ts中出错 (64,16):错误TS2314:泛型类型“Dispatch”需要1个类型参数 /home/me/dev/proj/typings/main/ambient/react redux/ind

TypeScript编译器在react-redux typings文件中报告错误,尽管我已将typings目录排除在tsconfig中

打字稿版本:1.8.10

下面是我得到的错误

/home/me/dev/proj/typings/main/ambient/react redux/index.d.ts中出错 (64,16):错误TS2314:泛型类型“Dispatch”需要1个类型参数

/home/me/dev/proj/typings/main/ambient/react redux/index.d.ts中出错 (68,21):错误TS2314:泛型类型“ActionCreator”需要1个类型参数

/home/me/dev/proj/typings/main/ambient/react redux/index.d.ts中出错 (95,13):错误TS2314:泛型类型“Store”需要1个类型参数

typings.json:

{
    "ambientDependencies": {
        "es6-shim": "registry:dt/es6-shim#0.31.2+20160602141504",
        "material-ui": "registry:dt/material-ui#0.15.0+20160602140214",
        "query-string": "registry:dt/query-string#3.0.0+20160331065456",
        "react": "github:DefinitelyTyped/DefinitelyTyped/react/react.d.ts#f407264835650f5f38d4bb2c515a79e7a835916b",
        "react-addons-css-transition-group": "registry:dt/react-addons-css-transition-group#0.14.0+20160316155526",
        "react-addons-transition-group": "registry:dt/react-addons-transition-group#0.14.0+20160417134118",
        "react-dom": "github:DefinitelyTyped/DefinitelyTyped/react/react-dom.d.ts#ca5bfe76d2d9bf6852cbc712d9f3e0047c93486e",
        "react-redux": "registry:dt/react-redux#4.4.0+20160501125835",
        "react-tap-event-plugin": "registry:dt/react-tap-event-plugin#0.0.0+20160226083632",
        "require": "registry:dt/require#2.1.20+20160316155526",
        "socket.io-client": "registry:dt/socket.io-client#1.4.4+20160317120654"
    }, 
    "dependencies": {
        "es6-promise": "registry:npm/es6-promise#3.0.0+20160211003958",
        "radium": "registry:npm/radium#0.16.6+20160310030142",
        "redux-thunk": "registry:npm/redux-thunk#2.0.0+20160525185520",
        "webpack": "registry:npm/webpack#1.12.9+20160418172948"
    }
}
tsconfig.json:

{
    "version": "1.8.10",
    "compileOnSave": false,
    "compilerOptions": {
        "module": "commonjs",
        "target": "es5",
        "jsx": "react",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true
    },
    "exclude": [
        "node_modules",
        "typings"
    ]
}
为什么它要从排除的目录报告错误?如何消除这些错误

更新:

正如Mike在回答中所建议的,问题在于react-redux定义使用的是redux的dt定义,而不是redux附带的定义。为redux安装dt定义确实可以消除这些错误,但这不是我的选择,因为我自己的代码使用redux附带的定义文件中定义的泛型类型


所以我真正的问题是:如何阻止TypeScript报告typings目录中文件中的错误?我认为将“typings”设置为排除目录之一可以阻止这种情况,但事实并非如此

看起来,
react redux
的dt定义依赖于,它们不同于npm模块,您可能依赖于npm模块

从dt安装
redux
的环境(全局)定义应该可以解决此问题

typings安装dt~redux--global--save

TS打字空间很乱


当您为
react-redux安装dt类型定义时,它会去除任何依赖项,迫使您自己安装每种定义,这一事实使事情变得更加混乱。

谢谢您的回答。是的,你是对的,但不幸的是,你建议的解决方案不是我的选择。请参阅我的问题BTW中的更新,从dt存储库安装redux typings的给定命令对我不起作用,我需要>typings install redux--ambient。听起来您使用的是typings库的1.0之前版本。至于您更新的问题,我想我只需要更新您的代码,以使用针对redux的dt类型,否则您将不会有针对react redux的类型或任何其他依赖于dt redux类型的redux lib类型。