如何在我的项目中包含非官方的打字稿定义文件?

How do I include an unofficial typescript definition file in my project?

我正在尝试包含一个不在 definitelytyped github 存储库中的 typings 定义文件,因此我认为我无法使用终端中的 typings 安装它。有谁知道我应该如何将它包含在我的 Angular 2 typescript 项目中?

我要包含的定义文件是 paper.js 库的定义文件,位于此处 https://github.com/sqwk/paper.d.ts

在您的根项目文件夹中,创建一个 manual_typings 文件夹并添加 paper.d.ts 文件。当你 运行 Typescript 编译器时,它会读取定义并且不会抱怨这个库。您可以将 manual_typings 文件夹命名为您想要的任何名称。这是我遵循的模式。

放置文件的位置取决于您如何配置 tsconfig.json file. The "moduleResolution" property can be set to Classic or Node, this will define how TypeScript will search your folder structure for paper.d.ts. The details on how it will look through you folder structure can be found here

实际上,您可以直接从 github:

使用打字来安装它
typings install github:sqwk/paper.d.ts/paper.d.ts --save --global

有关键入有效位置的更多信息here

sqwk/paper.d.ts - 是 org/repo。

/paper.d.ts - 是路径.

您还可以通过将 #commit-id 添加到路径来定义特定的提交:

typings install github:sqwk/paper.d.ts/paper.d.ts#0c45e2c25d3190fbedfcee998074356e58a392a9 --save --global