docs-devkit icon indicating copy to clipboard operation
docs-devkit copied to clipboard

fix: properly handle promise generics

Open hansemannn opened this issue 6 months ago • 0 comments

This pull request improves the TypeScript code generation in the documentation generator by enhancing type handling, especially for generics and union types. The changes ensure that generated TypeScript code is more accurate and syntactically correct, particularly when dealing with complex types like generics, union types involving functions, and Promises.

Type handling improvements:

  • Updated DocsParser to correctly extract the base type name before generics (e.g., strips <T> from Type<T>) when splitting namespaces, preventing issues with generic type names.
  • Modified GlobalTemplateWriter to parenthesize function types within union types, preventing TypeScript syntax errors (e.g., outputs (a: string) => void | number as ((a: string) => void) | number).
  • Enhanced generic type support in GlobalTemplateWriter by adding explicit handling for Promise<T> types, ensuring standard TypeScript generic syntax is used for Promises.

hansemannn avatar Aug 19 '25 08:08 hansemannn