Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lexical-markdown] Refactor: Update regExpEnd optional type in MultilineElementTransformer #6919

Conversation

untilhamza
Copy link

@untilhamza untilhamza commented Dec 8, 2024

[lexical-markdown] Refactor: Broaden regExpEnd optional type to boolean

Description

Current Behavior:
In the MultilineElementTransformer interface, the regExpEnd property's optional field was unnecessarily restricted to only accept true as a value. This strict typing didn't provide any practical benefit and limited potential use cases where false might be a valid state.

Changes:

  • Modified the type definition of optional in regExpEnd from true to boolean
  • This change allows for more flexible usage of the optional flag
  • Makes the type definition more intuitive and consistent with typical boolean flag patterns

Closes #[issue number]

Test plan

Before

The regExpEnd type was overly restrictive:

regExpEnd?: RegExp | {
  optional?: true;  // Could only be true
  regExp: RegExp;
};

After

The regExpEnd type now allows both true and false values:

CopyInsert
regExpEnd?: RegExp | {
  optional?: boolean;  // Can be either true or false
  regExp: RegExp;
};

This change maintains backward compatibility while providing more flexibility in how the optional flag can be used.

Copy link

vercel bot commented Dec 8, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 8, 2024 3:14am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 8, 2024 3:14am

@facebook-github-bot
Copy link
Contributor

Hi @untilhamza!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

Copy link

github-actions bot commented Dec 8, 2024

size-limit report 📦

Path Size
lexical - cjs 31.11 KB (0%)
lexical - esm 30.98 KB (0%)
@lexical/rich-text - cjs 40.11 KB (0%)
@lexical/rich-text - esm 32.8 KB (0%)
@lexical/plain-text - cjs 38.68 KB (0%)
@lexical/plain-text - esm 30.11 KB (0%)
@lexical/react - cjs 42 KB (0%)
@lexical/react - esm 34.15 KB (0%)

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot facebook-github-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 Dec 8, 2024
Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

The reason why you would use optional?: true is to make it clear that the default is false, and that there's no reason to specify it otherwise. I'm not sure this really has any benefit, there are other places in the code where an optional true is used as the type (such as discrete?: true and skipTransforms?: true), so if this change was desired I would expect that it would be done to the whole project. Does anyone else have opinions on this? @zurfyx @ivailop7

Generally speaking it's best to use types to limit the number of possible runtime states that should to be considered. {x?: boolean} has 4 states and {x?: true} has 3 (one less each when exactOptionalPropertyTypes is used)

@untilhamza
Copy link
Author

untilhamza commented Dec 8, 2024

The reason why you would use optional?: true is to make it clear that the default is false, and that there's no reason to specify it otherwise. I'm not sure this really has any benefit, there are other places in the code where an optional true is used as the type (such as discrete?: true and skipTransforms?: true), so if this change was desired I would expect that it would be done to the whole project. Does anyone else have opinions on this? @zurfyx @ivailop7

Generally speaking it's best to use types to limit the number of possible runtime states that should to be considered. {x?: boolean} has 4 states and {x?: true} has 3 (one less each when exactOptionalPropertyTypes is used)

@etrepum , this is actually very insightful - thank you. However I did not know the default was false as I could not tell from just looking at the types. Is there a way to explicitly tell the user of the function that the default is false while keeping the type as true?

@etrepum
Copy link
Collaborator

etrepum commented Dec 8, 2024

The type itself already says that either the setting doesn't mean anything at all, or the default is not true. What you could do to make it more explicit for people who don't understand that implication is to add more documentation to the type.

@untilhamza
Copy link
Author

I see what you mean. I will close this PR for now. Thanks for sharing the thinking behind it.

@untilhamza untilhamza closed this Dec 9, 2024
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants