https://i.sstatic.net/3hIOo.png
I'm encountering an issue while attempting to add a method to my Typescript class using prototype. Visual Studio is giving me a warning that the function does not exist in the target type.
I came across some information suggesting that I need to declare an additional interface for my type, which would include the definition of the method I want to add. However, it's not entirely clear to me how I should proceed after importing my type with import
. Simply trying:
import { EcommerceCartItem } from "../classes/EcommerceCartItem";
interface EcommerceCartItem {
myMethod: any
}
EcommerceCartItem.prototype.myMethod = function () {
return null;
};
...causes a conflict between the import declaration and the local declaration of EcommerceCartItem
. So, what would be the correct approach in this situation?