Skip to content
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

Open
1 task done
mgreystone opened this issue Oct 25, 2024 · 1 comment
Open
1 task done

[Bug]: In addOptions. the type of this.parent is wrong. #5768

mgreystone opened this issue Oct 25, 2024 · 1 comment
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug

Comments

@mgreystone
Copy link
Contributor

mgreystone commented Oct 25, 2024

Affected Packages

core

Version(s)

2.9.1

Bug Description

When extending a node & implementing addOptions, the type of this.parent is incorrect.

For a Node<T>, this.parent is typed as () => T, denoting that it is safe to call directly like this.parent(). However, this.parent might be undefined, as is documented, so we must call this.parent?.().

Because of the inaccurate type, it is easy to forget to add the ?. optional chaining. Furthermore, linting rules such as no-unnecessary-condition can automatically strip the ?. out, which can cause type errors be thrown at runtime.

import { Heading, type Level } from '@tiptap/extension-heading'

const MyHeading = Heading.extend({
  addOptions() {
    const levels: Level[] = [1,2,3]
    return {
      ...this.parent(), // this throws even though typescript says it is safe
      levels,
    }
  }
})

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

  • Yes, I've updated all my dependencies.
@mgreystone mgreystone added Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug labels Oct 25, 2024
@nperez0111
Copy link
Contributor

Yep, you are right here. Pushing a patch for it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Type: Bug The issue or pullrequest is related to a bug
Projects
None yet
Development

No branches or pull requests

2 participants