Types not found

寵の児 提交于 2020-01-11 12:28:09

问题


I just updated angular-cli (v1.1) and created a new project using ng new MyProj. Then I added and installed two dependencies to the project.json file:

"dependencies": {
    ...
    "toastr": "2.1.2",
    "spin": "0.0.1"
  },
  "devDependencies": {
    ...
    "@types/toastr": "2.1.32",
    "@types/spin": "2.3.30",
    ...
    "typescript": "~2.3.3"
  }

Then I updated the autogenerated app.component.ts adding this constructor:

constructor() {
    toastr.success('Hi')
}

The IDE (visual studio code) do not return any error but when I serve the application using ng serve I get the following error:

ERROR in ../A/src/app/app.component.ts (15,5): C annot find name 'toastr'.

I really cannot figure out what is wrong with that.

Thanks a lot


回答1:


I solved the problem removing types from tsconfig.app.json. This is the new configuration:

{
    "extends": "../tsconfig.json",
    "compilerOptions": {
        "outDir": "../out-tsc/app",
        "module": "es2015",
        "baseUrl": ""
    },
    "exclude": [
        "test.ts",
        "**/*.spec.ts"
    ]
}



回答2:


Try doing import * as toastr from 'toastr' or import toastr from 'toastr' - the latter is if it has a default export.



来源:https://stackoverflow.com/questions/44421367/types-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!