fix: correct return type of getDefaultReactSlashMenuItems to include key#2416
fix: correct return type of getDefaultReactSlashMenuItems to include key#2416ysds wants to merge 1 commit intoTypeCellOS:mainfrom
Conversation
The return type was missing the `key` property, causing type errors when accessing `item.key` on returned items.
|
@ysds is attempting to deploy a commit to the TypeCell Team on Vercel. A member of the Team first needs to authorize it. |
| >( | ||
| editor: BlockNoteEditor<BSchema, I, S>, | ||
| ): (DefaultReactSuggestionItem & { | ||
| key: keyof Omit<Dictionary["slash_menu"], "page_break">; |
There was a problem hiding this comment.
I don't think this is correct right? Aren't you marking all of the items as having a page_break key, when that is not actually the case. Shouldn't you change DefaultReactSuggestionItem instead?
There was a problem hiding this comment.
Thanks for taking a look. I’ll check it out.
There was a problem hiding this comment.
To clarify, Omit<Dictionary["slash_menu"], "page_break"> here represents "a union of keys excluding page_break", not "marking items as having a page_break key". This pattern follows the same approach used in the DefaultSuggestionItem.ts
I believe the current implementation is correct, but I do agree that modifying DefaultReactSuggestionItem could be a better approach.
However, changing DefaultReactSuggestionItem requires a deeper understanding of BlockNote's design decisions. The key property was removed from DefaultReactSuggestionItem in #652, but the PR doesn't explain why. I can only speculate on the reasons:
- Potential conflicts with React's
keyprop - Custom suggestion items may not need a
key
Making changes to DefaultReactSuggestionItem feels beyond my current understanding of the codebase. This PR at least addresses the immediate type issue.
Summary
Fix incorrect return type of
getDefaultReactSlashMenuItems()to properly include thekeyproperty.Rationale
Items returned by
getDefaultReactSlashMenuItems()actually contain akeyproperty (inherited fromgetDefaultSlashMenuItems()), but the return typeDefaultReactSuggestionItem[]omitskey. This causes type errors when users try to accessitem.key:Changes
getDefaultReactSlashMenuItems()to includekeypropertygetPageBreakReactSlashMenuItems()by removing unnecessaryOmitImpact
item.keywithout type errorsTesting
Screenshots/Video
N/A (type-only change)
Checklist
Additional Notes