From 900de6b5b883fa49ebeb951757f782ee3857deaf Mon Sep 17 00:00:00 2001 From: Edoardo Scibona <12040076+velut@users.noreply.github.com> Date: Sat, 27 Apr 2024 01:09:16 +0200 Subject: [PATCH] docs: explain why type aliases are not expanded --- src/extract-type-alias.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/extract-type-alias.ts b/src/extract-type-alias.ts index b699576..d075a65 100644 --- a/src/extract-type-alias.ts +++ b/src/extract-type-alias.ts @@ -29,6 +29,16 @@ export const extractTypeAlias = async ( }); const typeAliasSignature = async (declaration: TypeAliasDeclaration): Promise => { + // Using `declaration.getType().getText(declaration);` returns the expanded/resolved type. + // However this causes: + // - inline imports like `import('...').SomeType` to appear in the signature + // - types can become really long in some cases as they are expanded by the compiler + // - format flags like `TypeFormatFlags.NoTruncation | TypeFormatFlags.UseAliasDefinedOutsideCurrentScope` + // seem to be ignored or cause local types to be resolved to their name like `type Foo = Foo;` + // For these reasons we simply get the type alias text as written by authors. + // See: + // - https://github.com/dsherret/ts-morph/issues/453#issuecomment-427405736 + // - https://twitter.com/drosenwasser/status/1289640180035403776 const signature = declaration.getText(); return formatSignature("type", signature); };