[Bug]: TypeError/regression introduced in 2.10.1: All options can be undefined
#5859
Description
Affected Packages
react, core, all extensions
Version(s)
2.10.1
Bug Description
Code that was previously working fine, now gives a TypeError when trying to access properties on this.options
. These two examples were working fine in Tiptap 2.9, but now give errors:
Example 1
import Paragraph from "@tiptap/extension-paragraph";
import { mergeAttributes } from "@tiptap/react";
const MyStrangeParagraph = Paragraph.extend({
renderHTML({ HTMLAttributes }) {
return [
`h1`,
mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 'undefined' is not assignable to 'Record<string, any>'
0,
];
},
});
Example 2
import Link, { type LinkOptions } from "@tiptap/extension-link";
interface MyLinkOptions extends LinkOptions {
myFunc: () => void;
}
const MyLink = Link.extend<MyLinkOptions>({
addCommands() {
return {
...this.parent?.(),
myNewCommand: () => () => {
this.options.myFunc();
// ^^^^^^^^^^^^^^^^^^^ Object possibly 'undefined'
},
};
},
});
MyLink.configure({ myFunc: () => undefined });
Browser Used
Chrome
Code Example URL
No response
Expected Behavior
For example 1, I would expect this to work. I'm not sure how this can be done without using a non-null assertion this.options.HTMLAttributes!
or without writing extra logic that wasn't previously necessary.
For example 2, I recognise that MyLink can be configured without passing in myFunc
, so maybe the old code was wrong and there should always have been a nullish check such as this.options?.myFunc()
. But shouldn't it be possible to provide mandatory options?
Additional Context (Optional)
Introduced with release 2.10.1 with #5854.
Also, I understand that the options
types may be more correct now, but these changes are breaking type changes and according to Renovatebot, which we are using in our project, the passing percentage for this update is quite low, indicating there have been breaking changes. I don't know if this specific type change is the breaking change for everyone, but it is for us. See the below screenshot that shows Renovatebot stats for some of the packages.
Dependency Updates
- Yes, I've updated all my dependencies.