Skip to content

Feature: CustomPrintNodeFn should be able to return undefined #7612

@ehamberg

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:

const customPrint: string | undefined = customPrintNode
? customPrintNode(node, obfuscateText)
: undefined;
if (customPrint !== undefined && customPrint.length > 0) {
return customPrint;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions