Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for FlowType definitions #22

Open
far-blue opened this issue Jul 1, 2017 · 3 comments
Open

Support for FlowType definitions #22

far-blue opened this issue Jul 1, 2017 · 3 comments

Comments

@far-blue
Copy link

far-blue commented Jul 1, 2017

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.

@gaperton
Copy link

gaperton commented 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 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.

@gaperton
Copy link

gaperton commented Mar 7, 2018

TypeScript type annotations support is here.

https://volicon.github.io/Type-R/#definitions-in-typescript

@gaperton
Copy link

gaperton commented Mar 7, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants