Angular 4, ng2-redux: Could not find a declaration

2019-08-27 00:31发布

问题:

I installed latest Angular from git clone https://github.com/angular/quickstart.git

and

npm i --save redux-logger redux ng2-redux

Here .../node_modules/redux-logger/src/index.js there's

export { defaults, createLogger, defaultLogger as logger };

Error:TS7016:Could not find a declaration file for module 'redux-logger'. '.../node_modules/redux-logger/dist/redux-logger.js' implicitly has an 'any' type.

import { applyMiddleware, createStore } from 'redux';
import logger from 'redux-logger';
//import { createLogger } from 'redux-logger';

const store = createStore(
  rootReducer,
  applyMiddleware(logger)
);

//const store = createStore(
//  rootReducer,
//  applyMiddleware(createLogger())
//);

The same error when using createLogger()

How to fix that?

Thanks.

回答1:

You must be using typescript. In order to import any javascript library/module, you need its corresponding type declarations which are generally included in DefinitelyTyped.

Do:

npm i @types/redux-logger --save-dev

The package is here. Then you can import as:

import { createLogger } from 'redux-logger';


标签: angular redux