1 | import * as tsm from 'ts-morph';
|
2 |
|
3 | export function getApparentType({
|
4 | declaration,
|
5 | }: {
|
6 | declaration: tsm.Node;
|
7 | }): string {
|
8 | // See https://github.com/dsherret/ts-morph/issues/453#issuecomment-427405736
|
9 | // and https://github.com/dsherret/ts-morph/issues/453#issuecomment-667578386
|
10 | return declaration
|
11 | .getType()
|
12 | .getApparentType()
|
13 | .getText(
|
14 | declaration,
|
15 | tsm.ts.TypeFormatFlags.NoTruncation |
|
16 | tsm.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope
|
17 | )
|
18 | .replace(/^Number$/, 'number')
|
19 | .replace(/^Boolean$/, 'boolean')
|
20 | .replace(/^String$/, 'string');
|
21 | }
|