Skip to content

An error occurs when passing the SourceFile node to getTypeAtLocation. #62190

@cy-hub-cloud

Description

@cy-hub-cloud

🔎 Search Terms

getTypeAtLocation && SourceFile

🕗 Version & Regression Information

  • This changed between versions ______ and _______
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

No response

💻 Code

//ModuleA
export let namedOther = null;
//ModuleB
import  * as testNs from './ModuleA';
export { testNs };

🙁 Actual behavior

In the statement 'export { testNs }', call getTypeAtLocation on 'testNs' to retrieve its type.

🙂 Expected behavior

It is expected to obtain the returned type, whether the result is errorType or another type, but in reality, an error 'Cannot read properties of undefined (reading 'kind')' will be reported in getTypeAtLocation#getTypeOfNode#isDeclarationNameOrImportPropertyName.

Additional information about the issue

The getTypeOfNode function supports passing a SourceFile node, but if the condition isExternalModule is not met, the SourceFile node will proceed to execute further.
Image

When executing the isDeclarationNameOrImportPropertyName method, the passed node is still the SourceFile node, and an error is directly reported at name.parent.
Image
Image

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: APIRelates to the public API for TypeScriptNeeds More InfoThe issue still hasn't been fully clarified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions