Skip to content

[lexical-mark] Chore: Widen MarkNode method return types to boolean#8717

Merged
etrepum merged 4 commits into
facebook:mainfrom
patrick-atticus:mark-node-types
Jun 19, 2026
Merged

[lexical-mark] Chore: Widen MarkNode method return types to boolean#8717
etrepum merged 4 commits into
facebook:mainfrom
patrick-atticus:mark-node-types

Conversation

@patrick-atticus

Copy link
Copy Markdown
Contributor

Description

MarkNode overrides canInsertTextBefore, canInsertTextAfter, and canBeEmpty from the base ElementNode, but narrowed their return types from boolean to the literal false. This prevents anyone extending MarkNode from overriding these methods to return true.

For example, if you have a custom node (eg some CommentNode) that you want to allow the user to extend with canInsertTextAfter, it will no longer satisfy the MarkNode types.

This PR widens the three return types back to boolean to match ElementNode, restoring type compatibility for subclasses. MarkNode's own behaviour is unchanged: each method still returns false.

Test plan

Before

A subclass overriding any of these methods to return true fails to type-check:

class CustomMarkNode extends MarkNode {
  canBeEmpty(): boolean {
    return true; // TS error: not assignable to `false`
  }
}

After

The same subclass type-checks successfully, and MarkNode's default behaviour is unchanged (all three still return false).

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 18, 2026
@vercel

vercel Bot commented Jun 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Jun 19, 2026 1:57am
lexical-playground Ready Ready Preview, Comment Jun 19, 2026 1:57am

Request Review

Comment thread packages/lexical-mark/src/MarkNode.ts Outdated

@potatowagon potatowagon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed by Navi (Tater Thoughts Bobblehead) on behalf of @potatowagon.

Assessment: LGTM

This is a straightforward type-widening change in MarkNode — relaxing the return types of 4 override methods from literal types (false, true) to boolean.

What I checked:

  • Correctness: The runtime behavior is unchanged — each method still returns the same literal value (false or true). Only the TypeScript return-type annotation is widened.
  • Motivation: This aligns with Lexical's ongoing effort to deprecate unsafe narrow type parameters (see #8661). Widening to boolean allows subclasses to override with different values without type errors — the narrow literals were unnecessarily restrictive for a method that semantically returns a boolean flag.
  • Backward compatibility: Widening a return type from a literal to its base type is a covariant change — existing callers expecting boolean (the base class signature) are unaffected. Code that was relying on the literal type for type narrowing is extremely unlikely for these methods.
  • www compat: No removed exports, no renamed methods, no behavioral changes. Safe for Meta's internal consumers.
  • Test coverage: No new tests needed — this is purely a type annotation change with no runtime effect. Core unit tests (22.x + 24.x), browser tests, and integrity checks all pass.
  • Edge cases: None — literal narrowing removal has no runtime edge cases.

CI Status: Core tests all green (unit 22.x ✓, unit 24.x ✓, browser ✓, integrity ✓). CLA signed. Vercel deployed. E2e canary pending but irrelevant for a type-only change.

Ready to approve.

Co-authored-by: James Fitzsimmons <119275535+james-atticus@users.noreply.github.com>
Comment thread packages/lexical-mark/src/MarkNode.ts Outdated
@etrepum etrepum added this pull request to the merge queue Jun 19, 2026
Merged via the queue into facebook:main with commit c2eb19c Jun 19, 2026
42 checks passed
@etrepum etrepum mentioned this pull request Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

4 participants