Incompatible Promoted Readonlies

no-email (Damien Seguy), Damien Seguy
Tue, 03 Sep 2024 00:00:00 +0000

Promoted properties allows the creation of properties directly from the constructor signature.
readonly properties are only written once, and cannot be written again.
When a promoted property is public or protected, it cannot be used in two constructor's signature, as the first instance is immediately written, and cannot be changed again.
This doesn't happen with private, which keeps the properties distinct in the class and its parent. This still may produce confusion.
It is then possible to only use one promoted property definition, and skip that parameter in the other constructor; or make the second a simple parameter, rather than a promoted property.