作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我喜欢用 rx-node在 TypeScript 中
import RxNode from 'rx-node';
我安装了rx-node使用 npm
$ npm install rx-node --save
我搜索了类型定义,但没有任何结果
$ typings search rx-node
No results found for search
如何为已安装的 npm 模块定义自定义类型定义 rx-node ?我应该在哪里存储类型定义文件?如何配置 TypeScript(tsconfig.json 和 typings.json)?
编辑:感谢Aleksey L.和 David Bohunek我实现了定义一个看起来像这样的 rx-node.d.ts
declare module "rx-node" {
import {Observable} from '@reactivex/rxjs';
import {ReadLine} from "readline";
function fromReadLineStream(stream: ReadLine): Observable<string>
}
我安装了@reactivex/rxjs
npm install --save @reactivex/rxjs
因为我遇到了错误
node_modules\@reactivex\rxjs\dist\cjs\Observable.d.ts (10,66): Cannot find name 'Promise'. (2304)
我将 tsconfig.json 中的目标更改为 es6
。
最佳答案
请注意,这是关于使用 typings 管理定义的老问题 (2016)不赞成通过npm直接安装它们
您可以将自定义定义添加到 typings.json。例如具有以下文件夹结构:
/typings
/custom
rx-node.d.ts
/global
...
其中 rx-node.d.ts 是您的自定义类型文件。例如:
declare module RxNode {
export interface ...
}
然后用命令安装
typings install file:typings/custom/rx-node.d.ts --save --global
或手动:在 typings.json 中添加对该类型文件的引用:
{
"name": "TestName",
"version": false,
"globalDependencies": {
"rx-node": "file:typings/custom/rx-node.d.ts"
}
}
然后运行 typings install
关于node.js - TypeScript:如何为已安装的 npm 包定义自定义类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37641960/
我是一名优秀的程序员,十分优秀!