TypeScript resolve referenced Interface

Answered

Hello, I'm unable to find a way to resolve Interface fields within PSI.
When I have f.e. two Interfaces:

interface A {
field: string;
}
interface B {
a: A;
}

When I get PSI of B, I get JSTypeImpl class, which contains "A" type. Problem I'm strugling with is, how to get PSI element of "A" even when it is imported and/or aliased.
I'm just trying to list all fields "B" has, but now I have only that field "a" is of "A" type.

I suppose, there is an existing function somewhere within JSLanguage, but I can't find it.

JSResolveUtil.getElementJSType() // returns back itself
ES6PsiUtil.resolveSymbolInModule() // There I'm not even sure what has to be context and scope

Does anyone by a chance have a clue, where to look for it?

2 comments
Comment actions Permalink

Hello, if I understand your question correctly, I'd suggest to use the following methods:

  1. TypeScriptPropertySignature.getJSType() to get JSTypeImpl of a: A
  2. JSTypeImpl.getDeclarations() to resolve TypeScriptInterfaceImpl A.
  3. TypeScriptInterfaceImpl.getFields() or other methods to get members of A

Alternatively, to get interface A you can use TypeScriptPropertySignature.getTypeElement().getReferenceExpression().resolve() or multiResolve(false)

1
Comment actions Permalink

Yes, thats what I needed, thank you.

0

Please sign in to leave a comment.