Install ts-node
with Node.js v13+ then you can run:
./node_modules/.bin/ts-node -O '{"module":"commonjs"}' list-exports.ts <files...>
The -O '{"module":"commonjs"}'
part is to allow using import
& export
statements: TypeStrong/ts-node#922 (comment)
Running the script on example.ts
:
./node_modules/.bin/ts-node -O '{"module":"commonjs"}' list-exports.ts ./example.ts
Will print the following:
File names: ./example.ts
export specifier something
export specifier alias
export var blah
export var a
export var b
export function testing
export specifier testing2
export function MyInterface
export function MyType
[
'something', 'alias',
'blah', 'a',
'b', 'testing',
'testing2', 'MyInterface',
'MyType'
]
The array printed at the end is a list of exported names/identifiers.
Check it against what you would expect from example.ts
.
There may be missing cases. No problem!
- Use https://astexplorer.net/ !
- Change the parser to
typescript
. - Enter your code in the left editor panel
- Preview the AST on the right panel
- Edit the
list-exports.ts
to catch the case you want and then add new identifiers/names toallExports
array.