flowgen icon indicating copy to clipboard operation
flowgen copied to clipboard

Abstract classes

Open Kiechlus opened this issue 7 years ago • 6 comments

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,
    ...
}

Kiechlus avatar Jun 10 '17 04:06 Kiechlus

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?

roelandmoors avatar May 27 '18 16:05 roelandmoors

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 ?

DavidBabel avatar Sep 28 '18 08:09 DavidBabel

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 avatar Sep 28 '18 08:09 DavidBabel

@DavidBabel Flowgen uses AST parsing to destruct and rebuild the definition files. Regexes work in isolation but not on an entire language.

joarwilk avatar Sep 30 '18 22:09 joarwilk

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 avatar Oct 03 '18 20:10 DavidBabel

@DavidBabel enums are implemented now

goodmind avatar Feb 08 '19 03:02 goodmind