benmerckx / genes

Generates split ES6 modules and Typescript definitions from Haxe modules.
43 stars 8 forks source link

comment docs for typedef with optional fields #63

Closed Antriel closed 2 years ago

Antriel commented 2 years ago

I have a Haxe typedef, which exports as TS's type = { ... }, which is great, but that format doesn't seem to support comment docs.

I could change my Haxe typedef to an interface (as long as I don't actually use it from Haxe, as I want to keep using it as anonymous object). But then I lose @:optional. Which could be fixed by adding ?, for Null<T> types, to the name in the generated d.ts files.

Possibly better approach would be to (optionally?) generate correct interfaces directly for Haxe's typedef. Would that make sense, or am I missing something?

benmerckx commented 2 years ago

This is more of an oversight. The Haxe compiler supplies comments for generation if they start with /** and in case of anonymous types only in their "long form". But they were not being generated for typedefs and anonymous types. I just fixed the generation in fcbd3cd2638bc9d30392213df0a820dfe29bd969, so this should work (although the formatting could use some work):

// slash-slash comments are ignored
typedef A = {
  /** this won't end up in the generated files either, it's the "short" notation */
  prop: String
}

/** this should be there */
typedef B = {
  /** and this */
  var prop: String;
}
Antriel commented 2 years ago

That was fast! I knew about the Haxe issues, and your fix does export the comments successfully, but VSCode doesn't show me the documentation.

I think the issue is that VSCode doesn't look into type for documentation, so having

export type Config = {id?: null | string, name?: null | string, /**
Defaults to the last instanced project.
*/
project?: null | Project}

won't help here. Which brings me back to the idea of generating interfaces instead of type declarations.

benmerckx commented 2 years ago

This would seem to be caused by the formatting issues :) With proper newlines (102ac271119a5884d5f47c1582bb75f036f71f32) typescript picks up the comments

image

Antriel commented 2 years ago

Awesome, that works, thanks! :)