1

I was adding a property to string.

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

by doing something like this,

Now, When I use it

const abc = 'abc'.capitalize()

typescript throws an error

Property 'capitalize' does not exist on type 'string'.

Alwaysblue
  • 9,948
  • 38
  • 121
  • 210
  • Does this answer your question? [How to extend String Prototype and use it next, in Typescript?](https://stackoverflow.com/questions/39877156/how-to-extend-string-prototype-and-use-it-next-in-typescript) – Tobias S. Sep 30 '22 at 19:53

0 Answers0