GithubHelp home page GithubHelp logo

Comments (4)

cprcrack avatar cprcrack commented on June 18, 2024 1

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?

from marked.

UziTech avatar UziTech commented on June 18, 2024 1

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)

from marked.

UziTech avatar UziTech commented on June 18, 2024

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

from marked.

cprcrack avatar cprcrack commented on June 18, 2024

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.

from marked.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.