简体   繁体   English

使用Awesome Typescript Loader处理.d.ts文件

[英]handling .d.ts files with Awesome Typescript Loader

I've recently upgraded my Angular2 version to the Final one and have a problem with awesome-typescript-loader that wants one declaration file. 我最近将Angular2版本升级到了最终版本,并且awesome-typescript-loader有一个问题,需要一个声明文件。 How can I do it and where to link that typings file? 我该怎么做以及在哪里链接该打字文件? I use the angular2-webpack-starter . 我使用angular2-webpack-starter I have a few .d.ts files in my app providers definitions. 我的应用程序提供商定义中有一些.d.ts文件。

For now all the tries to compile them end with something like: 现在,所有尝试编译它们的尝试都以类似以下内容结束:

Module build failed: Error: Debug Failure. False expression: Output generation failed
at Object.assert (node_modules\typescript\lib\typescript.js:2407:23)
at Object.transpileModule (node_modules\typescript\lib\typescript.js:54401:18)
at State.fastEmit (node_modules\awesome-typescript-loader\src\host.ts:264:39)
at transform (node_modules\awesome-typescript-loader\src\index.ts:164:28)
at transformationFunction (node_modules\awesome-typescript-loader\src\index.ts:89:48)
at compiler (node_modules\awesome-typescript-loader\src\index.ts:105:34)
at Object.loader (node_modules\awesome-typescript-loader\src\index.ts:18:18)
@ ./src/app/providers/socket/index.ts 6:9-40
@ ./src/app/providers/socket/chat-service.ts
@ ./src/app/pages/restricted/restricted.ts
@ ./src/app/app.routes.ts
@ ./src/app/app.module.ts
@ ./src/app/index.ts
@ ./src/main.browser.ts
@ multi main

The advice from ATL readme: ATL自述文件的建议:

All declaration files should be resolvable from the entry file. The easiest way to do this is to create a references.d.ts file which contains references to all of your declaration files. Then reference references.d.ts from your entry file.

Thanks in advance! 提前致谢!

I excluded .d.ts files from input sources and instead defined the location of .d.ts files using the typingsRoot property of tsconfig.json. 我从输入源中排除了.d.ts文件,而是使用tsconfig.json的typesRoot属性定义了.d.ts文件的位置。 It does seem silly that an error should be thrown when an input file results in no output. 当输入文件导致无输出时应该抛出错误似乎很愚蠢。 This would be fairly common such as a file containing only an interface definition. 这将是相当普遍的,例如仅包含接口定义的文件。

As my .d.ts files contained interfaces only, I've renamed them all to [something] .interface.ts . 由于我的.d.ts文件仅包含接口,因此我将它们全部重命名为[something] .interface.ts Now I've just custom-typings.d.ts that is linked in tsconfig.json for other things. 现在,我只是在tsconfig.json链接了custom-typings.d.ts来进行其他操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM