Skip to content

Commit 900de6b

Browse files
committed
docs: explain why type aliases are not expanded
1 parent d746c3f commit 900de6b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/extract-type-alias.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ export const extractTypeAlias = async (
2929
});
3030

3131
const typeAliasSignature = async (declaration: TypeAliasDeclaration): Promise<string> => {
32+
// Using `declaration.getType().getText(declaration);` returns the expanded/resolved type.
33+
// However this causes:
34+
// - inline imports like `import('...').SomeType` to appear in the signature
35+
// - types can become really long in some cases as they are expanded by the compiler
36+
// - format flags like `TypeFormatFlags.NoTruncation | TypeFormatFlags.UseAliasDefinedOutsideCurrentScope`
37+
// seem to be ignored or cause local types to be resolved to their name like `type Foo = Foo;`
38+
// For these reasons we simply get the type alias text as written by authors.
39+
// See:
40+
// - https://github.com/dsherret/ts-morph/issues/453#issuecomment-427405736
41+
// - https://twitter.com/drosenwasser/status/1289640180035403776
3242
const signature = declaration.getText();
3343
return formatSignature("type", signature);
3444
};

0 commit comments

Comments
 (0)