You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are tools to automatically convert Typescript definitions to Flowtype definitions which do a pretty good job and at least give a starting point for further manual improvement. However, these tools seem to need a single merged Typescript definition file to work from. I've tried creating a merged d.ts file and it failed - maybe dues to issues mentioned in other issues - but I'm not a Typescript expert.
Would someone consider attempting the (automatic) creation of an index.js.flow definition from the typescript definitions as a starting point and then the ingoing inclusion of the index.js.flow file in the npm package? I assume it would be up to those using Flow to improve and extend the definition file and fix errors but this is much easier if there's a half-decent starting point.
At the time, even TypeScript typings are very far from being perfect. It's going to change in future, but in my opinion, it doesn't make sense to convert them to Flow at this time.
The main problem with type annotations is the declaration of Record's attributes which are being generated from the class spec, and their static types must be are a bit different from those in the declaration.
That happens because of the type coercion. For instance. If you have an attribute with type MyModel, it's not only legal to assign an object to this attribute, but it has the special meaning.
record.myModel = new MyModel(); will replace the model with new one.
record.myModel = { a : 1 } will modify an existing model in place with record.myModel.set({ a : 1 }), or create such a model if an attribute is empty. The same thing happens to collections.
Therefore the right TS type for the attribute is Partial<MyModelAttributes>, and unfortunately, it's not the type which is extracted from the TS class spec.
Both @attr( spec ) and @type( Ctor ).as decorators can be used in conjunction with Flow definitions, once the major issue with Flow annotations will be resolved. I would accept the corresponding PR.
Activity
gaperton commentedon Nov 16, 2017
At the time, even TypeScript typings are very far from being perfect. It's going to change in future, but in my opinion, it doesn't make sense to convert them to Flow at this time.
The main problem with type annotations is the declaration of Record's attributes which are being generated from the class spec, and their static types must be are a bit different from those in the declaration.
That happens because of the type coercion. For instance. If you have an attribute with type MyModel, it's not only legal to assign an object to this attribute, but it has the special meaning.
record.myModel = new MyModel();will replace the model with new one.record.myModel = { a : 1 }will modify an existing model in place withrecord.myModel.set({ a : 1 }), or create such a model if an attribute is empty. The same thing happens to collections.Therefore the right TS type for the attribute is
Partial<MyModelAttributes>, and unfortunately, it's not the type which is extracted from the TS class spec.gaperton commentedon Mar 7, 2018
TypeScript type annotations support is here.
https://volicon.github.io/Type-R/#definitions-in-typescript
gaperton commentedon Mar 7, 2018
Both
@attr( spec )and@type( Ctor ).asdecorators can be used in conjunction with Flow definitions, once the major issue with Flow annotations will be resolved. I would accept the corresponding PR.