From what I understand, TypeScript does not make a distinction between prototype properties and instance properties. Additionally, there is no built-in detection for Object.defineProperty
on the prototype, which is unlike a feature for typechecking JavaScript.
Therefore, is the conventional method to create a prototype property simply by declaring it and defining it outside the class, without TypeScript being able to verify this?
class C {
declare readonly x: string;
}
Object.defineProperty(
C.prototype,
'x',
{ value: 'something' },
);
In my specific scenario, I am extending the Error
class and aim to override Error.prototype.name
. It appears that the most effective approach is to add a prototype property on the subclass.