bluebird icon indicating copy to clipboard operation
bluebird copied to clipboard

promisfyAll doesn't work with TypeScript 3.9 emitted code

Open sluukkonen opened this issue 4 years ago • 1 comments

(This issue tracker is only for bug reports or feature requests, if this is neither, please choose appropriate channel from http://bluebirdjs.com/docs/support.html)

Please answer the questions the best you can:

  1. What version of bluebird is the issue happening on? 3.7.2

  2. What platform and version? (For example Node.js 0.12 or Google Chrome 32) Node.js 12

  3. Did this issue happen with earlier version of bluebird?

TypeScript 3.9 emits the following kind of code with "esModuleInterop": true for importing modules, due to this change

Source code:

// @ts-nocheck
import * as Bluebird from 'bluebird'
import * as fs from 'fs'

const promisified = Bluebird.promisifyAll(fs)

console.log(promisified.readFileAsync) // undefined

Compiled code:

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
exports.__esModule = true;
// @ts-nocheck
var Bluebird = __importStar(require("bluebird"));
var fs = __importStar(require("fs"));
var promisified = Bluebird.promisifyAll(fs);
console.log(promisified.readFileAsync); // undefined

This change causes Bluebird.promisifyAll to fail to add any promisified methods, since util.inheritedDataKeys ignores getters if in ES5 mode.

I'm not sure who is to blame here (so to speak), but opening this issue in any case.

sluukkonen avatar May 19 '20 12:05 sluukkonen

So the bug is specifically for es modules being promsified?

I'm fine with adding a check for the specific case there

benjamingr avatar May 19 '20 15:05 benjamingr