Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript errors in react-redux typings file

The TypeScript compiler is reporting errors in the react-redux typings file, even though I have excluded the typings directory in tsconfig.

TypeScript version: 1.8.10

Here are the errors I'm getting

ERROR in /home/me/dev/proj/typings/main/ambient/react-redux/index.d.ts (64,16): error TS2314: Generic type 'Dispatch' requires 1 type argument(s).

ERROR in /home/me/dev/proj/typings/main/ambient/react-redux/index.d.ts (68,21): error TS2314: Generic type 'ActionCreator' requires 1 type argument(s).

ERROR in /home/me/dev/proj/typings/main/ambient/react-redux/index.d.ts (95,13): error TS2314: Generic type 'Store' requires 1 type argument(s).

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"
    ]
}

Why is it reporting errors from an excluded directory? How can I eliminate these errors?

Update:

As Mike suggested in his answer, the problem is that the react-redux definitions are using the dt definitions for redux, and not the ones that ship with redux. Installing the dt defintions for redux does indeed take these errors away, but this is not an option for me since my own code uses the generic types defined in the definitions file that ships with redux.

So my real question is this: How can I stop TypeScript from reporting errors in files from the typings directory? I thought that setting 'typings' as one of the exclude directories would stop this, but it doesn't.

like image 968
Dominic Avatar asked Oct 19 '22 07:10

Dominic


1 Answers

It looks like the dt definitions for react-redux have a dependency on the dt definitions for redux, these differ from the ones bundled with the redux npm module, which it looks like you may be relying on.

Installing the ambient (global) definitions of redux from dt should resolve the issue.

typings install dt~redux --global --save

The TS typing space is messy.

The fact that when you install dt type definitions for react-redux it strips any dependencies forcing you to install each yourself makes things that bit more confusing.

like image 105
Mike Stead Avatar answered Oct 21 '22 01:10

Mike Stead