microsoft / microsoft/TypeScript
An error occurs when passing the SourceFile node to getTypeAtLocation.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
### 🔎 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
```ts
//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.
When executing the `isDeclarationNameOrImportPropertyName` method, the passed node is still the `SourceFile` node, and an error is directly reported at `name.parent`.
_No response_
Contributor guide
Research direction
Start by reproducing the supplied ModuleA/ModuleB example and trace getTypeAtLocation through getTypeOfNode, isExternalModule, and isDeclarationNameOrImportPropertyName. Verify that passing the SourceFile node no longer causes the name.parent error and that getTypeAtLocation returns a type or errorType as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100