-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Feature: CustomPrintNodeFn should be able to return undefined #7612
Copy link
Copy link
Closed
Labels
enhancementImprovement over existing featureImprovement over existing featuregood first issueGood for newcomersGood for newcomers
Description
Lexical version: 0.31.2
Steps To Reproduce
- Use a
TreeViewfrom@lexical/react/LexicalTreeViewan supply a customcustomPrintNodefunction. - (Implicitly) return
undefinedto get the default behaviour for nodes whose representation you don't want to override. - Type error due to
CustomPrintNodeFnreturn type beingstring.
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:
lexical/packages/lexical-devtools-core/src/generateContent.ts
Lines 261 to 266 in 36493cb
| const customPrint: string | undefined = customPrintNode | |
| ? customPrintNode(node, obfuscateText) | |
| : undefined; | |
| if (customPrint !== undefined && customPrint.length > 0) { | |
| return customPrint; | |
| } |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementImprovement over existing featureImprovement over existing featuregood first issueGood for newcomersGood for newcomers