flowgen
flowgen copied to clipboard
Abstract classes
I just started with flow and I am new to the topic of typed javascript. Among others, I need to convert this library.
When I run flowgen on it, it seems the whole abstract class abstract class Locator<E, L, V>
and its methods are omitted.
Why is this the case? Especially these methods are important and as they appear nowhere in the generated flow definition I think this will cause trouble...
Also I have seen than an enum was omitted:
export const enum State {
Fulfilled = 0,
...
}
I have the same problems with enums. It seems they are ignored. Probably because flow doesn't have any real eums.
But your state enum could be converted to something like this: export type State = 0 | 1 | ....
Not perfect, but better then nothing?
Actually typescript :
const enum CreativeOrderBy {
id = 'id',
advertiserId = 'advertiserId',
adFormatId = 'adFormatId',
name = 'name',
createdAt = 'createdAt',
updatedAt = 'updatedAt'
}
become flow 👍
declare type CreativeOrderBy =
| 'id'
| 'advertiserId'
| 'adFormatId'
| 'name'
| 'createdAt'
| 'updatedAt';
Why not add this logic, it's not a big deal, is it ?
This does the job, not a big deal
function buildEnum(TSschema) {
const nl = '\n';
let result = `${nl}${nl}// manually generated enum${nl}`;
const enumRegex = /const enum (\w+) {([\s\S]*?)}/gm;
let match;
do {
match = enumRegex.exec(TSschema);
if (match) {
const typeName = match[1];
const TSenums = match[2];
const flowEnum = TSenums.trim()
.replace(/ +/g, '')
.replace(/\w+ =/gm, ' |')
.replace(/,/gm, '');
result += `${nl}declare type ${typeName} =${nl}${flowEnum};${nl}`;
}
} while (match);
return result;
}
@DavidBabel Flowgen uses AST parsing to destruct and rebuild the definition files. Regexes work in isolation but not on an entire language.
This is clearly a work around, i understand it's not a solution.
I use this code in my project because the missing enum broke my front code. I guess it can help others
@DavidBabel enums are implemented now