joarwilk / flowgen

Generate flowtype definition files from TypeScript
Other
657 stars 87 forks source link

Do not apply exactness to types containing indexers #191

Closed namuol closed 2 years ago

namuol commented 2 years ago

I believe I have found an edge case affecting those using older versions of Flow (<0.126.0), which this PR aims to solve.

It's easiest to see what this PR does with some examples:

TypeScript input Before After
```ts type Map = { [key: string]: string; }; ``` ```js type Map = { [key: string]: string, ... }; ``` The `...` here is ignored by Flow, so it can be removed ```js type Map = { [key: string]: string, }; ```
Same as above with --no-inexact ```js type Map = {| [key: string]: string, |}; ``` Using indexers in exact objects was unsupported in Flow [up until v0.126.0](https://github.com/facebook/flow/blob/main/Changelog.md#01260). ```js type Map = { [key: string]: string, }; ``` Same as above; no exact syntax for types containing indexers. An "exact" object with an indexer doesn't really make sense, since the purpose of the indexer is to allow you to provide arbitrary keys, so removing exactness from an object with an indexer should be a no-op in Flow >=0.126.0 and should fix unusable types for older Flow versions

Thank you so much to all the contributors! ❤️ flowgen is a fantastic tool!

orta commented 2 years ago

dang - 60 versions behind :P

Cool, this seems reasonable to me - thanks for the well described PR!

orta commented 2 years ago

Shipped:

npm notice name:          flowgen                                 
npm notice version:       1.20.1