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

marked.parseInline() returns string | Promise<string> even when { async: false } #3101

Closed
cprcrack opened this issue Nov 21, 2023 · 4 comments · Fixed by #3103
Closed

marked.parseInline() returns string | Promise<string> even when { async: false } #3101

cprcrack opened this issue Nov 21, 2023 · 4 comments · Fixed by #3103

Comments

@cprcrack
Copy link

Marked version: 10.0.0

Describe the bug
marked.parseInline("markdown", { async: false }) returns a string | Promise<string>.

Expected behavior
marked.parseInline("markdown", { async: false }) should return a string. This is already the case with marked.parse("markdown", { async: false })

@UziTech
Copy link
Member

UziTech commented Nov 21, 2023

I think parseInline is actually correct. If an extension sets async: true then marked.parse(md, {async: false}) will still return Promise<string>

@cprcrack
Copy link
Author

cprcrack commented Nov 21, 2023

I only use this parseInline() method because parse() adds surrounding <p> tags to the output, which I don't want. I don't use any extension and it's a pain in the ass constantly having to write as string.

Why doesn't parse() suffer from the same issue? Does that method not support extensions? Shouldn't maybe an extension fail if you specify async: false and the extension cannot run synchronously? Not being able to predict the return type for the most basic usage of the method without any extensions seems a little bit poor regarding Typescript support.

Any other workaround to not have to do unsafe as string casting? Or any other way I can help?

@UziTech
Copy link
Member

UziTech commented Nov 21, 2023

Parse does the same thing. I think the types are wrong there. Unfortunately typescript isn't smart enough to know if an extension sets async: true.

The way that typescript recommends using typescript in this situation is to use as string if you know there are no async extensions or always await the output (will work even for string)

@cprcrack
Copy link
Author

Got it, it's a shame that Typescript cannot figure it out. I hoped that it may be something that could be easily fixed.

Thanks for the tip, didn't thought I could await a regular string, but that works and I prefer it to having unsafe castings. That way if I add an extension in the future (whatever those are for 😆) it will continue to work.

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

Successfully merging a pull request may close this issue.

2 participants