haxiomic / dts2hx

Converts TypeScript definition files (d.ts) to haxe externs (.hx) via the TypeScript compiler API
MIT License
134 stars 9 forks source link

Create Enum abstracts from keyof extensions #58

Open ciscoheat opened 3 years ago

ciscoheat commented 3 years ago

Apologizes if this has already been considered, but in the puppeteer file I see that there are some definitions like on<K extends keyof PageEventObj>, which looks like a good candidate for an enum abstract, similar to:

export interface PageEventObj {
  close: undefined;
  console: ConsoleMessage;
  dialog: Dialog;
  ...

Which is transformed to a non-constrained type parameter when used:

function on<K>(eventName : K, ...) : Page;

But since it is well-defined in the keys of the PageEventObj, could you define an enum:

enum abstract PageEventObjKey(String) {
    var close;
    var console;
    var dialog;
}

And use that as a type for eventName?