我希望我的TypeScript应用程序的编译失败,如果我没有与我使用的外部库对应的类型(TypeScript文件中已安装和引用)。目前,编译在没有它们的情况下是成功的。没有d.ts文件没有编译错误
这里是我的tsconfig.json
内容:
{
"compilerOptions": {
"target": "ES5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"noEmitOnError": false,
"declaration": true
}
}
这里是我想抛出错误的代码(toastr
变量没有定义,只有在运行时提供):
import {Component} from 'angular2/core';
@Component({
selector: 'my-app',
template: `
<div>Hello world</div>
`
})
export class AppComponent {
constructor() {
toastr.info('I am here for few seconds');
}
}
谢谢!
我不认为有一个简单的方法来做到这一点。 Typescript被写为JavaScript的超集,所以所有有效的JavaScript都是有效的Typescript。有效的JavaScript可以是无类型的,所以有效的Typescript可以是无类型的。 Typescript编译器可以内置它,但我不知道任何这样的功能。你可以尝试一个功能请求https://github.com/Microsoft/TypeScript/issues – AndyJ
Toastr在树中某个文件中的引用?这并不适合我,所以有些事情必定会有所不同。 – Fenton
你有没有理由不使用toastr类型? – rgvassar