angular - 如何将我的自定义 .d.ts 文件添加到我的 Angular 库中?

标签 angular typescript-typings yeoman-generator tsconfig

我使用 Yeoman 生成器库 ( https://github.com/jvandemo/generator-angular2-library ) 创建了 Angular 库。然后我想添加带有自定义类型的文件并将它们放入 src/types 文件夹中,但编译器看不到它们。

我尝试在类型中使用不同的路径,在 tsconfig.es5.json 中使用 typeRoots,但还没有成功。

创建了一个简单的 repo 重现了这个问题: https://github.com/yuriykuzin/ng2-sample-library

非常感谢任何帮助。提前致谢!

最佳答案

编译器使用 src/index.ts 作为主要入口点来确定要编译哪些文件。

如果您的类型没有导入到您的项目文件中,您必须将以下行添加到 src/index.ts 以告诉编译器包含这些类型:

import './types/sample-type';

这应该会生成 dist/types/sample-type.d.ts 并在 dist/index.d.ts 中引用。

关于angular - 如何将我的自定义 .d.ts 文件添加到我的 Angular 库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44026110/

相关文章:

AngularJS + Angular 8 不能一起工作 [混合应用]

javascript - Visual Studio Code 智能感知和 JavaScript ES5

yeoman - 找不到 'yo'二进制文件。确保已安装它并在$ PATH中。你能告诉我问题是什么吗?

node.js - Gruntfile.js 路径中的 `{,*/}` 是什么意思?

java - 使用 angular2 ngFor 迭代 Map 对象

angular - Firestore 错误 : The query requires an index

html - DIV ARIA-LABEl 未被 JAWS 读取

Typescript:空检查在 array.map 函数内不起作用

typescript - 无法扩展 sinon 的类型

node.js - Yeoman/NPM 错误 : node-gyp fails