dsherret / ts-morph

TypeScript Compiler API wrapper for static analysis and programmatic code changes.
https://ts-morph.com
MIT License
5.02k stars 196 forks source link

Add a way to figure out why a type has no Symbol #1573

Closed ofersadgat closed 2 months ago

ofersadgat commented 2 months ago

Is your feature request related to a problem? Please describe.

Yes, I have code as follows:

test.ts

import { SomeType } from 'place';
export const foo: SomeType;

and I get the type of foo with something like: const type = project.getSourceFile('test.ts').getExport('foo').getType(); which resolves...I do something like type.getText() which outputs: 'import("/node_modules/place/place").SomeType' which is correct (there is a file at "/node_modules/place/place.d.ts" which indeed has a SomeType export (and I can indeed see it if I manually look at that file and find the exports). But for some reason, type.getSymbol() returns undefined. The get getPreEmitDiagnostics calls on all the loaded files returns nothing.

Describe the solution you'd like

Some sort of diagnostic / info call stating that some symbol couldnt load because of a dependency not found or similar would be very helpful.

Describe alternatives you've considered

I can sometimes get by by trying to parse the type.getText() and then doing the loading myself which will then let me know if a file is missing, but this doesnt always work as the file will be there but the symbol be unable to load. I have also tried to manually resolve the properties of the symbol, but that starts hitting issues when the type is more complicated e.g. const foo: MyType<SomeOtherType>&AThirdType and basically results in a rewrite of tsc which would be insane.