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

2019-08-27 00:26发布

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.

标签: angular redux
1条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-27 01:19

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';
查看更多
登录 后发表回答