Generating typings for JS object generates duplicate entries for a function

Viewed 15

I have a js file that, when generating types, leads to duplicate entries for each function in the object.

test.js

const test = {
  /**
   *
   * @param {string} testID
   * @returns {void}
   */
  initialize(testID) {
    // I do nothing
  },
};

export default test;

test.d.js

export default test;
declare namespace test {
    /**
     *
     * @param {string} testID
     * @returns {void}
     */
    function initialize(testID: string): void;
    /**
     *
     * @param {string} testID
     * @returns {void}
     */
    function initialize(testID: string): void;
}

What gives?

1 Answers

The issue is in the declaration initialize(testID) vs initialize = function(testID)

This will generate perfectly:

const test = {
  /**
   *
   * @param {string} testID
   * @returns {void}
   */
  initialize: function(testID) {
    // I do nothing
  },
};

export default test;

yields:

export default test;
declare namespace test {
    function initialize(testID: any): void;
}

Related