microsoft / microsoft/TypeScript

Type alias circularly references itself

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

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

Domain: check: Type Circularity Help Wanted Possible Improvement
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

circular reference, generic, error TS2456, recursive

### 🕗 Version & Regression Information

- This is the behavior in every version I tried, and I reviewed the FAQ for entries about circular reference

### ⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.8.2#code/C4TwDgpgBAYg9nAKuaBeKBvAsAKClAMwQH4AuKAIwQBsIBDAOwG5cBfFnXUSKAIToDOEAKK0AthAbAAPIgB8UdPCQooAMky58AYwAWAS2oATAE6TyAYQCuA4HDGiIEqQG0Auh3zcI5RB3a4XKrWtvaOzsCKfIIi4pIyAOS6AIwJchxAA

### 💻 Code

```ts
type FooType = {
foo?: boolean;
};

type BaseElement = FooType & {
children: CustomElement[];
type: T;
};

type CustomElement = BaseElement<'h1'>;

```

### 🙁 Actual behavior

When defining a recursive type structure using a generic type, TypeScript incorrectly reports a `Type alias 'CustomElement' circularly references itself.(2456)` error, even though the type should be resolvable.
It gets weird when you move `type: T;` line above the `children: CustomElement[];` and the error disappears. Also removing `FooType` will resolve the issue.

### 🙂 Expected behavior

In the first place the code should not throw any errors, in the second place the behavior should not change by reordering records of a type.

### Additional information about the issue

_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 với bản tái hiện TypeScript Playground được liên kết và so sánh hai thứ tự thành viên trong kiểu giao generic. Truy vết chẩn đoán tham chiếu vòng cho các bí danh kiểu đệ quy và xác định lý do việc thêm FooType làm thay đổi chẩn đoán đó; hoàn thành khi cấu trúc đệ quy hợp lệ không còn báo TS2456 và thứ tự thành viên không làm thay đổi kết quả.

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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả 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.