While analyzing some TypeScript code, I stumbled upon a peculiar declaration within a class definition:
constructor(readonly constructorParam : Type) {
// no assignment of constructorParam here
}
Surprisingly, constructorParam
is still being used as usual.
Could it be that the constructorParam
property is automatically "created and assigned"?
This class is also wrapped in
export abstract class ... extends ... implements ...
(where extends
and implement
are standard inheritance keywords, and export
is typically used for module management).
LATEST UPDATE
After reading through this article, it appears that indeed, constructor parameters marked as readonly
are treated in this manner - creating and assigning values by default.