ckeditor5 icon indicating copy to clipboard operation
ckeditor5 copied to clipboard

[TS] Let's discuss how to use `readonly` and `protected`

Open Reinmar opened this issue 3 years ago • 0 comments

readonly

While working on #11708 we came across an difference in how we used JSDoc's @readonly and the semantics of TS's readonly keyword.

In TS's world, a readonly property cannot be modified after being initialized in the constructor (similar to const). So far, when migrating code we were defining properties as readonly if they were @readonly in JSDoc. 

However, before the migration we allowed changing this property if the change was happening inside the class. This was sometimes used and so we were using workaround such as: https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/range.ts#L795-L796

We need to revisit how we port the JSDoc's @readonly from the perspective of:

  • The code itself (how to migrate)
  • The API docs (how the API should be used by others)

The output of this work should be:

  • Clarification of when to use readonly now.
  • Migration tips.
  • ADR

protected

Similar to readonly – our semantics differs from the one used by TS. We need to clarify the change and come up with migration tips.

The output of this work should be:

  • Clarification of when to use protected now.
  • Migration tips.
  • ADR

Notes

  • This is a research ticket. Eventual code changes will be handled in a separate ticket.

Reinmar avatar Sep 12 '22 10:09 Reinmar