Y
Y
Yeah2017-08-17 12:39:23
Node.js
Yeah, 2017-08-17 12:39:23

typescript. Why does bluebird.promisify for fs.unlink still require a callback function?

Question for TS connoisseurs
We want to do unlink through the standard fs module. We use bluebird:

import { promisify } from 'bluebird';
await promisify(fs.unlink)(file);

And bam! we get an error that we need 2 arguments, not one. Because for some reason TS still thinks I should call unlink with file and cb parameters:
Error:(25, 27) TS2554:Expected 2 arguments, but got 1
.
import { promisify } from 'bluebird';
const _unlink = promisify(fs.unlink) as any;
await _unlink(file);

So it worked, but how to do it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kitmanov, 2017-08-17
@k12th

I would smoke the source codes on the subject of why this happens. At the very least, you can at least something like this:

interface StringToPromise {
    (string): Promise<object>;
}

const _unlink = promisify(fs.unlink) as StringToPromise;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question