找不到类型 [英] Types not found

查看:98
本文介绍了找不到类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚更新了angular-cli(v1.1),并使用ng new MyProj创建了一个新项目. 然后,我在 project.json 文件中添加并安装了两个依赖项:

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

然后我更新了自动生成的app.component.ts,并添加了以下构造函数:

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

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

IDE(Visual Studio代码)不返回任何错误,但是当我使用ng serve为应用程序提供服务时,出现以下错误:

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:C 找不到名称"toastr".

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.

非常感谢

推荐答案

我解决了从tsconfig.app.json中删除types的问题. 这是新配置:

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

这篇关于找不到类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆