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

Update CustomTransformer type #94

Merged

Conversation

UgRoss
Copy link
Contributor

@UgRoss UgRoss commented Jul 5, 2023

Update CustomTransformer type to support the false return. #93

Before:
Screenshot 2023-07-05 at 23 08 31

@@ -143,4 +143,4 @@ export type CalloutIcon =

export type CustomTransformer = (
block: ListBlockChildrenResponseResult
) => string | Promise<string>;
) => string | false | Promise<string | boolean>;
Copy link
Contributor Author

@UgRoss UgRoss Jul 5, 2023

Choose a reason for hiding this comment

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

It looks like that Promise<string | false> won't work because TS infers its type as Promise<boolean> when I try to only return false inside async callback.

Example:

n2m.setCustomTransformer("embed", async (block) => {
  return false;
});

Type 'Promise' is not assignable to type 'string | Promise<string | false>'

Copy link
Owner

Choose a reason for hiding this comment

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

That is because over here

if (!!customTransformerValue || customTransformerValue === "")

if the value is false then it's inferring type as string|true (since boolean can be true as well as false)

A simple fix is to just check the type of the returned value as string in the if statement in the above lines instead of checking true/false.

@souvikinator souvikinator merged commit 4a45e6f into souvikinator:master Jul 14, 2023
@souvikinator
Copy link
Owner

Thank you for your contribution. I made necessary changes and merged the PR. This fix should be live in the upcoming release along with other bug fixes

@UgRoss
Copy link
Contributor Author

UgRoss commented Jul 16, 2023

Thank you for your contribution. I made necessary changes and merged the PR. This fix should be live in the upcoming release along with other bug fixes

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants