Is there a way to promise node functions and get intellisense using Typescript?
I am using definitions @types
and added @types/bluebird
as expected, I get autocomplete when using methods from the library. However, I would like to promise node (fs) functions. I can do it 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 execute fsPromisified, I lose the autocomplete.
Can I do this without having to wrap node functions with promises?
source to share
You can use pre-promisified mz/fs
instead fs
, which wraps the whole promise of all async functions fs
(with their original names, not prefixed Async
). This package has TypeScript typings ( @types/mz
):
import * as fs from 'mz/fs';
// e.g., read file
fs.readFile('somefile')
.then((contents) => {
// ...
});
source to share