Comments (4)
Anyway, here are the contents of the source files:
index.js
// @flow
import {A} from "./a.js";
import {B} from "./b.js";
const a = new A(null);
const b = new B(a);
console.log("A = ", a);
console.log("B = ", b);
a.js
//@ flow
import type {B} from "./b.js";
export class A {
b: ?B;
constructor(b: ?B) {
this.b = b;
}
}
b.js
// @flow
import type {A} from "./a.js";
// The following line causes the problem. Removine the line and
// s/MaybeA/?A/ makes the file runnable.
type MaybeA = ?A;
export class B {
a: MaybeA;
constructor(a: MaybeA) {
this.a = a;
}
}
from babel-plugin-tcomb.
I have edited the generated b.js
a bit and it seems to fix the problem:
var MaybeA = _tcomb2.default.maybe(_a.A, "MaybeA");
becomes a lazy evaluating function with closure:
var MaybeA = function() { var _ty; return function() { if (!_ty) _ty = _tcomb2.default.maybe(_a.A, "MaybeA"); return _ty; } }();
And of course
_assert(a, MaybeA, "a");
becomes
_assert(a, MaybeA(), "a");
from babel-plugin-tcomb.
Flow allows for circular dependencies at the type-level. However babel-plugin-tcomb needs to reify those types at the value level so avoiding circular dependencies in the first place seems the best option.
I'm not sure that a lazy definition like that would handle all the use cases
from babel-plugin-tcomb.
Flow allows for circular dependencies at the type-level. However babel-plugin-tcomb needs to reify those types at the value level so avoiding circular dependencies in the first place seems the best option.
Sadly those circular dependencies are not always removable. Consider the case a parent object that owns a few children, and each children has a weak reference to the parent. This is a circular reference, but not a bad programming habit at all.
I'm not sure that a lazy definition like that would handle all the use cases.
No. By addingexport b_singleton = new B(null);
at the end ofb.js
, the lazy evaluations will be immediately invoked and still crash. However, declarations alone will not be able to crash the lazy definitions, be it type, function or class.
Anyway, unless we can put the definition of A in another file, we can't really be sure that the definitions will be loaded before it is executed. But I don't think we can do this with babel.
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?
- Add support for object type spread HOT 11
- 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.