Giter VIP home page Giter VIP logo

Comments (11)

gcanti avatar gcanti commented on August 23, 2024 1

IMO the better option would be to define a helper function (actually a new custom tcomb combinator) and inject it when needed, like assert or extend (see here https://github.com/gcanti/babel-plugin-tcomb/blob/master/src/index.js#L64). Since tcomb types are fully introspectable at runtime, you should be able to implement the required complex logic.

from babel-plugin-tcomb.

voldern avatar voldern commented on August 23, 2024

Gave it a try ☝️

from babel-plugin-tcomb.

gcanti avatar gcanti commented on August 23, 2024

These should be converted into a tcomb intersection

Based on this comment they are pretty different from intersections

from babel-plugin-tcomb.

voldern avatar voldern commented on August 23, 2024

Based on this comment they are pretty different from intersections

Ah, that's true. I was a bit quick on the trigger.

Seems like doing t.interface.extend() will be the right thing to do?

from babel-plugin-tcomb.

voldern avatar voldern commented on August 23, 2024

Updated PR to do interface.extend instead.

from babel-plugin-tcomb.

gcanti avatar gcanti commented on August 23, 2024

I'm afraid is not well suited: from the documentation of tcomb you linked

Note. Repeated props are not allowed (unless they are strictly equal)

Also, in absence of official documentaton (!), the following rules seem to apply

  • every property from spread becomes optional
  • every property before non-exact spread becomes mixed
  • properties after spread stay the same
  • $Exact changes the rules above

so the behavior is way different from t.interface.extend

from babel-plugin-tcomb.

voldern avatar voldern commented on August 23, 2024

Thank you so much for the feedback!

Aha. I misunderstood

Alternatively you can use the t.interface.extend(mixins: Array, options?: string | Options) => TcombType function:

To mean that I could use t.interface.extend to allow repeated props.

every property from spread becomes optional

Would an approach be to iterate over the properties in the interface being spread and make them into maybe by default, but not when the interface is $Exact<>?

every property before non-exact spread becomes mixed

We could do this by splitting properties into two groups, before and after spread and making those before spread mixed ?

And then maybe do some hand-wrangling to create a new interface directly?

from babel-plugin-tcomb.

voldern avatar voldern commented on August 23, 2024

Would a way to simplify this be to add an option to .extend() that allow overwrites that gets passed to mixin(). Or would you rather not allow this in plain tcomb ?

from babel-plugin-tcomb.

voldern avatar voldern commented on August 23, 2024

I've updated the PR and I think it takes in to account all of the strange rules surrounding object spread. How do you feel about the code, and the separation between what is done at compile time vs runtime?

from babel-plugin-tcomb.

gcanti avatar gcanti commented on August 23, 2024

How do you feel about the code, and the separation between what is done at compile time vs runtime?

Seems a good balance. Let me know when you consider the PR mergeable. If you agree I'll publish this feature tagged as Experimental for now

From the CHANGELOG file: A feature tagged as Experimental is in a high state of flux, you're at risk of it changing without notice.

because

  • the upstream feature seems still unstable
  • the feature must be tested in real world scenarios

from babel-plugin-tcomb.

voldern avatar voldern commented on August 23, 2024

👍

I've bumped the version and updated the changelog. Is there anything I've missed? If not I feel like its mergable.

from babel-plugin-tcomb.

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.