zxbodya / flowts

utility script to convert project from flow to typescript
76 stars 11 forks source link

Adding type annotations via flow type-at-pos? #30

Open meandmax opened 3 years ago

meandmax commented 3 years ago

Interesting concept. Wondering if this could be something that is also interesting for flowts: https://github.com/Airtable/typescript-migration-codemod/blob/main/src/typescript/flow_type_at_pos.ts

This would add annotations, where flow knows the type so it would increase type coverage. Just bringing that up in case you are interested.

zxbodya commented 3 years ago

Indeed that might be interesting, might be worth to experiment with.

However, I am a bit skeptical about how beneficial that would be - my feeling is that in most cases where annotations are missing - TypeScript can successfully infer them, and so adding more flow based types might only increase amount of fixes to be made manually…

Other thing in this direction, that might be more interesting to look into - codemod provided by flow team for "type first" type annotations - https://flow.org/en/docs/cli/annotate-exports/

Theoretically it should add type annotation are to be added only at module boundaries(which is generally what is preferred for typescript as well), and so - there should be not much noise from it, but noticeable improvement in type coverage. Yet to try using it…

meyer commented 3 years ago

oh neat, i was about to write something that uses type-at-pos to augment flowts. it would be real handy for cleaning up the implicit anys that pop up during conversion.