Answer the question
In order to leave comments, you need to log in
How to get the readonly property of a class to compile correctly?
There is a simple class
By default TypeScript uses readonly
only during the type checking phase. Properties get into JS itself without modifications:
class MyClass {
public readonly prop = 1
}
class MyClass {
constructor() {
Object.defineProperty(this, "prop", {
enumerable: true,
configurable: true, // <--
writable: true, // <--
value: 1
});
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question