[TS] Support Optional Properties in ObservableMixin (here: SingleBindChain) #13965
Labels
domain:ts
squad:core
Issue to be handled by the Core team.
type:improvement
This issue reports a possible enhancement of an existing feature.
Milestone
📝 Provide a description of the improvement
While developing our own plugins for CKEditor 5, we would prefer the
ObservableMixin
(here:SingleBindChain
) to support binding from/to optional values as well.Reproducer
The following will report an error in
LinkUI
if we define the command value (hereLinkCommand
, also requires change inCommand
) to be optional:ckeditor5/packages/ckeditor5-link/src/linkui.ts
Line 142 in f4d2045
To reproduce, just change these definitions to optional rather than enforcing either a value or
undefined
:ckeditor5/packages/ckeditor5-link/src/linkcommand.ts
Line 29 in f4d2045
and
ckeditor5/packages/ckeditor5-core/src/command.ts
Line 52 in f4d2045
Thus, for the given lines:
(side note: As not all commands require having a value, optional might even be the better choice here)
Suggestion
The suggestion is changing, for example (related to the example above):
ckeditor5/packages/ckeditor5-utils/src/observablemixin.ts
Lines 1277 to 1280 in f4d2045
to:
Most likely, other declaration should be adapted, too.
Workaround
Despite using
@ts-expect-error
(in favor of@ts-ignore
), you have to define your bound properties as not being optional but either requiring a value orundefined
just as it is done forLinkCommand
.As an alternative to this, redefine the given method via Module Augmentation, as also used in
augmentation.ts
:This, seems to require splitting up
bind
andto
, though, to (using theLinkUI
example from above):📃 Other details
If you'd like to see this improvement implemented, add a 👍 reaction to this post.
The text was updated successfully, but these errors were encountered: