简体   繁体   English

有没有办法宣传节点的功能并通过Typescript获得智能感知?

[英]Is there any way to promisify node's functions and get intellisense with Typescript?

I'm using @types definitions and added @types/bluebird , as expected I get autocomplete when using the methods from the library. 我正在使用@types定义并添加@types/bluebird ,正如预期的那样,当使用库中的方法时,我会获得自动完成。 However I would like to promisify node's functions (fs). 但是,我想宣传节点的功能(fs)。 I'm able to do that with the following line: 我可以用以下行来做到这一点:

import * as Promise from 'bluebird'
import * as fs from 'fs'

const fsPromisified = Promise.promisifyAll(fs)

The problem is that when I do fsPromisified I lose autocomplete. 问题是,当我做fsPromisified时,我失去了自动完成功能。

Is there any way I can do this without having to wrap around node's functions myself with promises? 有没有什么方法可以做到这一点,而不必自己用promises包围节点的功能?

You can use the pre-promisified mz /fs instead of fs , which wraps all promisifies all async fs functions (with their original names, not the Async prefix). 你可以使用pre-promisified mz /fs而不是fs ,它包含所有promisifies所有async fs函数(使用它们的原始名称,而不是Async前缀)。 That package has TypeScript typings ( @types/mz ): 该软件包具有TypeScript @types/mz@types/mz ):

import * as fs from 'mz/fs';

// e.g., read file
fs.readFile('somefile')
  .then((contents) => {
    // ...
  });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法在打字稿上使用 util.promisify 继承方法签名? - Is there any way to inherit method signature with util.promisify on typescript? 如何使用 Bluebird 保证 Node 的 child_process.exec 和 child_process.execFile 函数? - How to promisify Node's child_process.exec and child_process.execFile functions with Bluebird? VSCode中更智能的智能感知-有什么方法摆脱不必要的建议? - Smarter intellisense in VSCode - any way to get rid of unwanted suggestions? 有什么方法可以保证单边消息,例如工作程序消息或WebSocket消息? - Is there any way to Promisify Unilateral Messages such as Worker Messages or WebSocket Messages? 有正确的方法来传播arangojs吗? - Is there a proper way to promisify arangojs? 有没有办法让 VSCode 从他们的评论行中显示有关 JavaScript 函数的附加智能感知信息? - Is there a way to get VSCode to display addition intellisense information about JavaScript functions from their comment lines? 有什么方法可以获取与NodeJS中当前节点的标记名称不同的附近html节点? - Any way to get nearby html nodes different from current node's tag name in NodeJS? 在节点中导出函数时,是否有停止重复的方式? - Any way of stop repeating while exporting functions in node? 有没有办法让Intellisense在Visual Studio / MVC中工作而没有“ if(false)”黑客? - Is there any way to get Intellisense working in Visual Studio / MVC without the “if(false)” hack? Node.js - promisify readline - Node.js - promisify readline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM