1

I'm trying to add a method to an object, like so:

Y.prototype.x = function(){return 'x'}

And getting:

Property 'x' does not exist on type 'Y'

After googling and searching, I am still clueless tbh.

Minsky
  • 2,277
  • 10
  • 19
  • Do you get that error when adding `x` or is it when you try to read `x` later? – md2perpe Dec 18 '21 at 21:43
  • Does this answer your question? [How do you explicitly set a new property on \`window\` in TypeScript?](https://stackoverflow.com/questions/12709074/how-do-you-explicitly-set-a-new-property-on-window-in-typescript) – Clashsoft Dec 18 '21 at 22:08
  • What you are writing is javascript. You also need to add the type info to 'Y'. How you do that depends on where Y is defined. Search typescript module augmentation. – Aron Dec 18 '21 at 22:23
  • 1
    Your question is very open. You need to provide more input of what is your current code. How is Y declared and what value does it already contain? How is it created? – Panagiotis Bougioukos Dec 18 '21 at 23:33
  • Please provide a [mre] that clearly demonstrates the issue you are facing. Ideally someone could drop the code into a standalone IDE like [The TypeScript Playground (link here!)](https://tsplay.dev/mLL6vm) and immediately get to work solving the problem without first needing to re-create it. So there should be no pseudocode, typos, unrelated errors, or undeclared types or values. – jcalz Dec 19 '21 at 01:51

0 Answers0