microsoft / microsoft/TypeScript

An error occurs when passing the SourceFile node to getTypeAtLocation.

Đang mở
#62,190 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Domain: API Needs More Info
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

### 🔎 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.
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_

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện ví dụ ModuleA/ModuleB được cung cấp và lần theo getTypeAtLocation qua getTypeOfNode, isExternalModule và isDeclarationNameOrImportPropertyName. Xác minh rằng việc truyền nút SourceFile không còn gây ra lỗi name.parent và rằng getTypeAtLocation trả về một kiểu hoặc errorType như mong đợi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
typescript
Lĩnh vực
compilers
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.