-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: In addOptions
. the type of this.parent
is wrong.
#5768
Comments
Yep, you are right here. Pushing a patch for it |
Resolved with 2.10.0 |
Reopening because I'm going to revert this change. It is more trouble than it is worth. If someone can find a way to update the typings in a way that don't break people. Feel free to contribute |
Some context: The attempts to resolve this issue caused the following new type errors in code that was previously working: import Link from "@tiptap/extension-link";
const MyLink = Link.extend({
addOptions() {
//^^^^^^^^^^ Type error
return {
...this.parent?.(),
};
},
}); See #5852 for the issue about the error above. 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,
];
},
}); See #5859 for more details about the error above. So any attempts to fix this issue should also ensure that the aforementioned cases won't have any type errors. |
…osis#5860) * revert: "fix(core): update the typings to be that options and storage are partials on an extended config ueberdosis#5852 (ueberdosis#5854)" This reverts commit 87d63d8. * revert: "fix(core): update the typing of `addOptions`, `addStorage` to have an optional parent ueberdosis#5768 (ueberdosis#5770)" This reverts commit d2f366d.
That's a bummer, but i understand that it would require a breaking change to the types. Do we think that the change would be acceptable in version 3? We have to remember to add |
I would be willing to get it in version 2 if there were an easy way to handle it. I tired doing this for like an hour and basically what I had come up with was that the types of the first .create needs to be different than a .extend. This isn't the easiest thing to support especially since it is already generic over two parameters so it gets confusing very fast. |
Affected Packages
core
Version(s)
2.9.1
Bug Description
When extending a node & implementing
addOptions
, the type ofthis.parent
is incorrect.For a
Node<T>
,this.parent
is typed as() => T
, denoting that it is safe to call directly likethis.parent()
. However,this.parent
might beundefined
, as is documented, so we must callthis.parent?.()
.Because of the inaccurate type, it is easy to forget to add the
?.
optional chaining. Furthermore, linting rules such asno-unnecessary-condition
can automatically strip the?.
out, which can cause type errors be thrown at runtime.Browser Used
Chrome
Code Example URL
No response
Expected Behavior
In the
addOptions
method,this.parent
should have a type of(() => T) | undefined
to match the implementation & documentation.Additional Context (Optional)
No response
Dependency Updates
The text was updated successfully, but these errors were encountered: