Comments (11)
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.
Gave it a try
from babel-plugin-tcomb.
These should be converted into a tcomb intersection
Based on this comment they are pretty different from intersections
from babel-plugin-tcomb.
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.
Updated PR to do interface.extend
instead.
from babel-plugin-tcomb.
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.
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.
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.
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.
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.
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)
- Refinements example HOT 6
- Typechecking flow's inferred types
- Generator types
- Why generics are not supported
- arguments is not carried across during return type check
- Redux actions with constant string values
- Checking return value of generator function breaks the code HOT 2
- Working with Meteor's new reify HOT 1
- "ReactClass is not defined" error HOT 2
- Cannot set up for ReactNative project HOT 2
- support for argument spread
- add meta object for class?
- tcomb crashes when there are circular "import type" HOT 4
- inspecting function argument and return types
- Adding Custom Error Message to Flow-typed Refinement?
- babel 7 support HOT 3
- ReferenceError: $Values is not defined
- The $Call-way
- React Native: _t is not defined
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from babel-plugin-tcomb.