Feature/definitions
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 notexport
ed- Add
declare
keyword toexport
ed classes
- Add
- Remove all code from the remaining
functions
,classes
,consts
,lets
, andinterfaces
- 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 toname: Type | null | undefined
can probably be narrowed down in some cases - In Components
vs
,cs
, andcomponents
have the type{ [key: string]: VariableReference<any> | undefined }
while in the flow code they have the typeany
- 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>
inutilities
which I do not know the difference from normalIterator<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.
- If how this is export change some day, the original
- 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.