angular - 如何在 Angular 中使用自定义 Typescript 声明文件 (.d.ts)?
问题描述
我正在使用 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 项目中使用这个文件,但我似乎找不到如何做的很好的解释。我尝试了在网上找到的各种方法,包括将其添加到我tsconfig.json
的files
、include
或typeRoots
部分中,但我还没有找到正确的方法。无论我做什么,我仍然得到错误TS2304: Cannot find name 'InvoiceModel'
。我该怎么做?
解决方案
由于您尚未发布使用生成的打字稿声明文件的片段,并考虑到您的部分问题
我尝试了我在网上找到的各种东西,包括将其添加到文件、包含或 typeRoots 部分中的 >my tsconfig.json”
我推断您在某种程度上缺少对声明文件的引用。这是用三斜杠指令完成的。
您需要做的就是将下面的代码添加到您想将其用作第一行的任何位置。
/// reference path=".../path/to/file" />
推荐阅读
- azure-data-explorer - startofday(Timestamp) vs bin(Timestamp, 1d) - 有什么理由比另一个更喜欢一个吗?
- node.js - POST 请求返回 504 Online 但在本地工作
- python - 根据条件查找和替换字符串上的单词
- python - Tesseract - 有很多错误的数字重新定位
- python - Tkinter GUI 无响应
- qt - QGuiApplication::commitDataRequest:QML 窗口未绘制
- asp.net-core - 注册时上传图片给用户时出错?
- docker - 卷安装不适用于 docker-compose (MacOS)
- python - 获取python中ping命令接收到的数据包数
- typescript - 如何将单个 spa 浏览器内实用程序模块导入 TypeScript 包裹项目