Document custom methods primitive types in Javascript

13 Views Asked by At

I have defined some methods on primitive types for my project:

Object.defineProperties(String.prototype, {
    capitalize: {
        value: function () {
            return this.charAt(0).toUpperCase() + this.slice(1);
        }
    }
});

But the code editor (Vs Code) cannot identify this and simply presents the method as any.

I tried assigning the function directly and documenting it with JsDoc, but without success:

/** **CAPITALIZE**
 * @returns {string}
 */
String.prototype.capitalize = function () {
    return this.charAt(0).toUpperCase() + this.slice(1);
};
0

There are 0 best solutions below