GithubHelp home page GithubHelp logo

Comments (3)

esoterra avatar esoterra commented on May 31, 2024 3

I think what @Liamolucko might be suggesting is that variants be tagged, but unions be untagged in their JS representation, which is what I would personally vote for.

from jco.

alexcrichton avatar alexcrichton commented on May 31, 2024

I don't think that the current JS representation of variants is really all that great, and I think it'd be great to improve! I would ideally like to implement a representation trick where for:

variant url-like {
    literal(string),
    parsed(url),
}

struct url {
    // ... 
}

for that to be represented in JS as type UrlLike = string | URL. I believe we can do this because the url-like type has variants, each with a payload, each with a distinct JS class representing them, so cases can be determined by the class rather than using a discriminant. I think we'll still have to fall back to a discriminant for some cases, but I would hope that lots of cases could use a discriminant-less representation and delegate to type-checks for "checking the discriminant"

from jco.

guybedford avatar guybedford commented on May 31, 2024

Closing since unions have been removed.

from jco.

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.