Skip to content

Commit

Permalink
docs: explain why type aliases are not expanded
Browse files Browse the repository at this point in the history
  • Loading branch information
velut committed Apr 26, 2024
1 parent d746c3f commit 900de6b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/extract-type-alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ export const extractTypeAlias = async (
});

const typeAliasSignature = async (declaration: TypeAliasDeclaration): Promise<string> => {
// 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);
};

0 comments on commit 900de6b

Please # to comment.