【问题标题】:handling .d.ts files with Awesome Typescript Loader使用 Awesome Typescript Loader 处理 .d.ts 文件
【发布时间】:2016-12-07 10:53:13
【问题描述】:

我最近将我的 Angular2 版本升级到了最终版本,并且遇到了awesome-typescript-loader 需要一个声明文件的问题。我该怎么做以及在哪里链接该打字文件? 我使用angular2-webpack-starter。我的应用提供程序定义中有一些 .d.ts 文件。

目前所有编译它们的尝试都以类似以下内容结束:

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

来自 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.

提前致谢!

【问题讨论】:

    标签: angular typescript webpack


    【解决方案1】:

    我从输入源中排除了 .d.ts 文件,而是使用 tsconfig.json 的 typingsRoot 属性定义了 .d.ts 文件的位置。当输入文件导致没有输出时应该抛出错误似乎很愚蠢。这将是相当常见的,例如仅包含接口定义的文件。

    【讨论】:

      【解决方案2】:

      由于我的 .d.ts 文件仅包含接口,我已将它们全部重命名为 [something].interface.ts。现在我只是在tsconfig.json 中链接了custom-typings.d.ts 用于其他事情。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-05-04
        • 1970-01-01
        • 2017-08-31
        • 2017-02-02
        • 1970-01-01
        • 2017-04-26
        • 2019-07-08
        • 2015-11-22
        相关资源
        最近更新 更多