ngx-confirm在导入TS文件时给出错误

时间:2018-03-26 07:31:17

标签: angular

按照现有项目中的简单教程https://github.com/akmittal/ngx-confirm#ngxconfirm,给我错误,将以下内容导入component.ts文件

import { NgxConfirmModule } from 'ngx-confirm/ngx-confirm.module';

浏览器中带有黑色bacground的错误消息如下

 in [at-loader] ./node_modules/ngx-confirm/ngx-confirm.component.ts:32:3 
TS7008: Member 'confirmModal' implicitly has an 'any' type.
ERROR in [at-loader] ./node_modules/ngx-confirm/ngx-confirm.component.ts:49:5 
TS2322: Type 'null' is not assignable to type 'Confirm'.
ERROR in [at-loader] ./node_modules/ngx-confirm/ngx-confirm.component.ts:55:5 
TS2322: Type 'null' is not assignable to type 'Confirm'

我无法在任何地方找到这个。

2 个答案:

答案 0 :(得分:0)

检查noImplicitAny文件中的tsconfig值。

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false // <-----
  },
  "exclude": [
    "node_modules",
    "typings/main",
    "typings/main.d.ts"
  ]
}

将其设置为false以解决此错误。

答案 1 :(得分:0)

在为整个应用禁用noImplicitAny之前,仅仅因为一个小的依赖项缺少正确的输入,请尝试以下选项:

  1. "skipLibCheck": true添加到tsconfig.json compilerOptions
  2. 根据此处列出的建议,ngx-confirm.module的明确排序:Link
  3. 在typings.d.ts中添加:

    declare module 'ngx-confirm' {
      const lib: any;
      export = lib;
    }