Coder Social home page Coder Social logo

Flow Type Support about plank HOT 5 CLOSED

pinterest avatar pinterest commented on June 19, 2024
Flow Type Support

from plank.

Comments (5)

bkase avatar bkase commented on June 19, 2024

Cool! The only thing I see is a minor enhancement. For the Objective-C backend, we generate a comment next to the integer enum types:

typedef NS_ENUM(NSInteger, PIPinAttributionImageType) {
    PIPinAttributionImageTypeUnset /* unset */,
    PIPinAttributionImageTypeBoard /* board */,
    PIPinAttributionImageTypeInterest /* interest */,
    PIPinAttributionImageTypeUser /* user */
};

I think this information especially important in JavaScript since the Flow definition doesn't name the numbers (although it could). Perhaps we at least include the comments like we do in Objective-C:

export type PinAvailabilityType =
    | 1 /* in_stock */
    | 2 /* out_of_stock */
    | 3 /* preorder */
    | 4 /* unavailable */;

from plank.

bradencanderson avatar bradencanderson commented on June 19, 2024

For PinAvailabilityType -- why are we using numeric enums? Seems error-prone since enums are structurally typed.

type o1 = 1 | 2;
type o2 = 1 | 2;
const a: o1 = 1;
(a: o2) // o1 and o2 shouldn't be interchangeable

My opinion: we should require that descriptions are unique and short (maybe introduce another key field) and we should use those as enums instead. We can convert back to ints when sending them over the wire if desired.

from plank.

maicki avatar maicki commented on June 19, 2024

@bkase: Added the description to the integer enums.

@bradencanderson: The enum types are based on how it's defined in the PDK. We support integer and string enums.

E.g. This is a string enum:

"object_type": {
  "type" : "string",
  "enum": [
      { "default" : "none", "description" : "none" },
      { "default" : "board", "description" : "board" },
      ...
  ],
  "default": "none"
},

And that's an integer enum:

"container_type": {
    "type": "integer",
    "enum": [
        { "default" : 0, "description" : "none" },
        { "default" : 1, "description" : "carousel" },
        ...
    ]
},

from plank.

bradencanderson avatar bradencanderson commented on June 19, 2024

Integer enums seem problematic because they're structurally typed -- 0 | 1 is a subtype of 0 | 1 | 2, etc.

from plank.

rahul-malik avatar rahul-malik commented on June 19, 2024

Merged

from plank.

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.