如何使用 Angular 中的自定义 Typescript 声明文件 (.d.ts)?

How do I use a custom Typescript Declaration file (.d.ts) from within Angular?

我正在使用 TypeLite 从 Web API 项目中的一些 C# POCO 生成 Typescript 接口。这会生成如下文件:

// TypeLite.Net4.d.ts
declare namespace MyNamespace.Models {
    interface InvoiceModel {
        billingPeriodId: number;
        createdDate: Date;
        invoiceId: number;
        invoiceNumber: number;
        organizationId: number;
        paidDate: Date;
        total: number;
    }
}

我想在我的 Angular 项目中使用这个文件,但我似乎找不到关于如何做的很好的解释。我尝试了各种我在网上找到的东西,包括将它添加到 filesincludetypeRoots 部分的 tsconfig.json,但我还没有找到正确的方法去做吧。无论我做什么,我仍然收到错误 TS2304: Cannot find name 'InvoiceModel'。我该怎么做?

由于您尚未发布使用生成的打字稿声明文件的代码段,并考虑到您的问题部分

I tried various things I've found online including adding it to >my tsconfig.json in the files, include, or typeRoots sections"

我推断您不知何故缺少对声明文件的引用。这是用 tripple-slash-directives.

完成的事情

您需要做的就是将下面的代码添加到您想要将其用作第一行的任何位置。

/// reference path=".../path/to/file" />