Skip to content

Feature/definitions

Karl Henrik Elg Barlinn requested to merge feature/definitions into develop

Typescript definitions

It is a best attempt, so it might not work 100%

The initial typescript definition types were created as follows (loosely told)

  • Take all code from src remove everything which is not exported
    • Add declare keyword to exported classes
  • Remove all code from the remaining functions, classes, consts, lets, and interfaces
  • Use https://github.com/Khan/flow-to-ts to convert flow to typescript.
    • The tool is not perfect
    • getters and setters must be manually added back in
    • It crashed when using interface {}, so it was replaced with just {}
  • The result is something resembling typescript

Some additional notes about the definitions

  • Opaque types have no translatable concepts to typescript (that I know of)
  • Nullable types (name: ?Type) in flow are translated to name: Type | null | undefined can probably be narrowed down in some cases
  • In Components vs, cs, and components have the type { [key: string]: VariableReference<any> | undefined } while in the flow code they have the type any
    • This allows for type checking when accessing the outlined functions, which uses proxies
  • Some of the flow methods are missing return types, in the ts defs it correctly assumed they return void
  • There are some weird types such as $Iterator<T, U, V> in utilities which I do not know the difference from normal Iterator<T, U, V>. I assumed they are the same for the definition sake.
  • Exports have been changed so no definition file export something exported in another file.
    • If how this is export change some day, the original hotdrink file still contains the commented out exports.
  • Remove all import * as foo from './bar' imports as it does not work well when merging into one large file
  • Import reference from the same folder, we have no src sibling folder here!

Other changes

The typescript definitions are defined as they are in source, so I have to concatenate them all together to make it behave like the webpacked file does. To do this I wrote a small shell script generate_ts_types.sh, but so far it has only been tested on my computer (make sure it works elsewhere before merging). It also remove all imports and duplicate exports from the generated file.

There is no way of automating changes from flow, the typescript definitions must be manually updated.

It should be noted that flow type definitions can be the original flow type files, see StackOverflow question and npm tool. So to have the flow types its as simple as renaming some files.

Edited by Karl Henrik Elg Barlinn

Merge request reports