typescript - 如何扩展类型声明?

标签 typescript typescript-typings

我正在使用一个 npm 模块,该模块在DefinitelyTyped/DefinitelyTyped github 存储库中进行了声明,但该模块的类型不完整。

我已经提出了拉取请求来获取缺失的声明,但是在其被接受之前,我需要有一种方法来暂时扩展不完整的声明。

理想情况下,我希望能够在我的项目根目录中有一个 temporaryTypings.d.ts 文件,我可以在其中为我遇到的每种情况添加声明。

最佳答案

您可以从非 DefinitelyTyped 源安装定义,例如您的 DT 分支:

# (this example is taken from https://www.npmjs.com/package/typings )
# If you need a specific commit from github. 
$ typings install d3=github:DefinitelyTyped/DefinitelyTyped/d3/d3.d.ts#1c05872e7811235f43780b8b596bfd26fe8e7760

npm 因为 typescript 2 也可以从特定的 git 存储库安装模块。

关于typescript - 如何扩展类型声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39844981/

相关文章:

javascript - 只能包含特定列表中的元素的数组的 typescript 类型

typescript - TypeScript 编译时如何检查 Omit?

javascript - 如何在 typescript 中编写子类(React.Component)的类型定义?

javascript - 在 Typescript 声明文件中建模(较长)API

reactjs - 如何将 react-datetime 与 react + typescript 结合使用(在 tsx 中)

TypeScript: `T extends infer P` 中 P 的上下文是什么? (不清楚 `P`来自哪里)

node.js - 如何摆脱 "TypeError: req.pipe is not a function"Nestjs 和 fastify

node.js - 如何编写typescript可执行文件?

javascript - Jest 测试中 UnhandledPromiseRejectionWarning 的含义是什么?

typescript - 如何让编译器对对象数组与实例数组发出警告