Skip to content

Feature: CustomPrintNodeFn should be able to return undefined #7612

Closed

Description

@ehamberg

Lexical version: 0.31.2

Steps To Reproduce

  1. Use a TreeView from @lexical/react/LexicalTreeView an supply a custom customPrintNode function.
  2. (Implicitly) return undefined to get the default behaviour for nodes whose representation you don't want to override.
  3. Type error due to CustomPrintNodeFn return type being string.

The current behavior

TypeScript type-checking fails:

error TS2322: Type '(node: LexicalNode) => string | undefined' is not assignable to type 'CustomPrintNodeFn'.
       Type 'string | undefined' is not assignable to type 'string'.
         Type 'undefined' is not assignable to type 'string'.

The expected behavior

Type checking succeeds.

More info

The code allows returning undefined from customPrintNode to get the default behaviour:

https://github.com/facebook/lexical/blob/36493cb0efc9d5156185aa8db51223f41b0a9afe/packages/lexical-devtools-core/src/generateContent.ts#L261-L266

Activity

  1. added
    good first issue
    on Jun 8, 2025
  2. etrepum commented on Jun 8, 2025

    @etrepum
    Collaborator

    Seems like you've already sorted out what the fix could be, go ahead and submit a PR. Alternatively, your code can return an empty string instead of undefined which will have the same behavior as what you expect undefined to do.

  3. changed the title [-]Bug:[/-] [+]Feature: CustomPrintNodeFn should be able to return undefined[/+] on Jun 8, 2025
  4. added
    enhancement
    on Jun 8, 2025
  5. achaljhawar commented on Jun 10, 2025

    @achaljhawar
    Contributor

    can I work on this issue?

  6. etrepum commented on Jun 10, 2025

    @etrepum
    Collaborator

    Yes, anyone may submit a PR for any issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementgood first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions