microsoft / microsoft/TypeScript

Resolution order dependent circular heritage

Đang mở
#61,711 0 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: 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

resolution order dependent circular heritage, circular base type, circular mixin

### 🕗 Version & Regression Information

- This changed in #39675

However, it appears this PR was the first time that circular heritage was (consistently) reported. Therefore this issue has essentially always existed.

### ⏯ Playground Link

https://www.typescriptlang.org/play/?#code/PTAEDEEsA8FMBNSQGagJ4HsCuoDGGBbA2AOwBdQyALSAZ1ABtITZRsKMAnUWgd0jK4qlDKAAGAQVxkuABQAqAJQBMsMQDoAUPFi4GAQ06t8JWhWgAuUAElTZfSVyx5aAA6wAPGTewMqKTKcCiqwAHwA3JpRIKAAqrQIIjxUGLyUVPocJAxooPqgOu4kOo65GCTi8mJI9CxOtLSGuchc6caQnLhYBpwCaFoxEvTMADRtoMjM+gygRrQYDABuiYvTWKzwGLC1GBQEmWSwnFre7qAAIrBF8LQA8iQe8qGgALx5JGiR2ro9xgYNoACrQA3ppQKBXJwMK4rJdrncHgFIMsAKLIZC6MgAbQARJDoTiALoRTQAXyiOj0hlYJH0xForn0ThshwIoFB4JiUDgiBQ6GwPH4gmE1DoSQcSHIR2QTNgWnBp1Y1gIrgYsGI5EykHKrxsdgcThc7g85wwXQ1ZAAwv9aJbypMAOa46ysokk8nfKlGPA2lnq9lg0CWC5XUg3e4eJGo9GY3H41xuyIerkwRJ8zA4IwEDDLcZiADKWAARka1KAHaQjpBcBDDHTYIdjpoqQCgUElKoPIWSz5dQ40M9YNBDsV6G32cmwNy06gM7N1TnWNRWAXi6XqhWWL0a4zOPXG1oW-QXergp3u6W+x9B8Ow8fWROosxGzLmabzaQrTa7SRHQHOVOqa8rOApCA4FbiIqfiAtIcgdmWMiQT40Ftmenj9qEYiBm2VhQf4sHtiEXwARAQFICBOBgSQEFiHhfoEGh1SIbRyGoCeDHwR4GFYeC7G4ax9FoUmFI-NSPr6K20jIrAaIYtIoBDiONygNakCfu+WAWgAsjAzAABQAEISbAUYyTG0gAJT-hCUIwqAJCaUWRzCZ6vwTFgjhkNqFSqepZqaZ+OnQMwHiBimPLkfyOAMBgGAJBUy54OUZh7s+bCoGIRkJNaEm0BogZZbAOUAopd72bAaR6eo1WGA6tBWP2WKElZLzPBgRYAFaYiMmihIZxlWIVxW0BZg3GcNXyUm5R6gIVpmyZi1kmClWAEVVNWcHVsKhqOEbseoyqquqn5auUoQWUmQA

### 💻 Code

```ts
// Fixed if you comment this line out or switch to `ActorPTR2e`.
declare const x: InstanceType;

// Used to show that only a dependency on `T` is necessary for the circularity.
// As in, the final resolved value does not matter.
type DependsOn = any;

declare class Actor {
prop: DependsOn;
}

declare namespace Item {
// Fixed if you switch this to an interface.
type Implementation = InstanceType;
}

declare class Item {
x: DependsOn;
}

// Fixed if you remove the `SubType` generic parameter.
class ActorPTR2e extends Actor {}

// Fixed if you remove the `SubType` generic parameter.
class ItemPTR2e extends Item {}

interface DocumentClassConfig {
// Fixed if you change `typeof ActorPTR2e` to `typeof ActorPTR2e`
Actor: typeof ActorPTR2e;

// Fixed if you change `typeof ItemPTR2e` to `typeof ItemPTR2e`
Item: typeof ItemPTR2e;
}

declare class ActiveEffect extends ClientDocumentMixin(BaseActiveEffect) {
prop: number;
}

declare function ClientDocumentMixin<
// Fixed if you loosen the constraint of `BaseClass`.
BaseClass extends new (...args: any[]) => object,
>(Base: BaseClass): BaseClass;

declare class BaseActiveEffect {
constructor(...args: DependsOn);
}
```

### 🙁 Actual behavior

Numerous errors, namely:
```
Type alias 'Implementation' circularly references itself.
Type 'ActiveEffect' recursively references itself as a base type.
'ActiveEffect' is referenced directly or indirectly in its own base expression.
'args' is referenced directly or indirectly in its own type annotation.
```

### 🙂 Expected behavior

No error, as seen when you comment out the line `declare const x: InstanceType;`. The error going away indicates that this circularity is resolution order dependent.

I understand how odd the code is out of context but I did actually run into this in a real codebase.

### 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à lần theo các chẩn đoán đã báo cáo về bí danh kiểu tuần hoàn, kiểu cơ sở và chú thích xoay quanh InstanceType, tính kế thừa của lớp generic và các ràng buộc mixin. Hoàn thành khi bản tái hiện không còn báo cáo các lỗi phụ thuộc vào thứ tự phân giải này mà không thay đổi ví dụ để tránh tính tuần hoàn.

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ó
5/5
Thời gian dự kiến
Hơn một tuần
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.