joarwilk / flowgen

Generate flowtype definition files from TypeScript
Other
658 stars 78 forks source link

bugfix: fix import type for enums #139

Closed SebastienGllmt closed 3 years ago

SebastienGllmt commented 3 years ago

Background:

1) Typescript enum is converted to a regular object type by flowgen 2) Typescript allows you to do import type on an enum type. However, Flow doesn't allow you to import type on a regular object type 3) To allow enum values as a function parameter in Flow, you need to accept $Values<...> as the argument

Bug: 1) Using import type on an enum generated invalid Flow that tried to import an object as a type. 2) Code using enums as types was using the generated object directly as the type, but it needs to use the $Values<...> Flow notation

Fix: 1) The new code now uses import typeof which is valid Flow notation 2) $Values is properly used for enums

orta commented 3 years ago

Cool, nice write-up, makes sense 👍🏻