microsoft / microsoft/TypeScript

Missing constraint error in instantiation expression for a nested class

Đang mở
#61,982 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.

Bug Domain: check: Variance Relationships Help Wanted
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

instantiation expression caching class expression declaration type arguments type parameter

### 🕗 Version & Regression Information

- This changed in PR: https://github.com/microsoft/TypeScript/pull/59931 , cc @weswigham

### ⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250701#code/MYGwhgzhAECCA8AVaBeaA7ArgWwEYFMAnAPmgG8AoaaANzBE3wEIAuaRAbiumAAsBLEABNW0AJLoIAFzDpg+RAE8ADvnhSV+APYAzOADoAQvASJi5jtAD0V6FIEwIvLZmHQihLYQrdpYKfzA0IaoPOBQwUjuAB5S+OhCMLChsKSU1NTKYITxUqKc3AC+XIUUQA

### 💻 Code

```ts
class A {
value!: T;
child!: InstanceType>>; // this should error

static B = class B {
parent!: T;
};
}
```

### 🙁 Actual behavior

It doesn't error

### 🙂 Expected behavior

it should error with:
```
Type 'A' does not satisfy the constraint 'A'.
Type 'T' is not assignable to type 'number'.(2344)
```

like it did in 5.6: [TS playground](https://www.typescriptlang.org/play/?ts=5.6.3#code/MYGwhgzhAECCA8AVaBeaA7ArgWwEYFMAnAPmgG8AoaaANzBE3wEIAuaRAbiumAAsBLEABNW0AJLoIAFzDpg+RAE8ADvnhSV+APYAzOADoAQvASJi5jtAD0V6FIEwIvLZmHQihLYQrdpYKfzA0IaoPOBQwUjuAB5S+OhCMLChsKSU1NTKYITxUqKc3AC+XIUUQA)

### Additional information about the issue

The problem here is that the situation is a little bit circular and variances worker gets hits in reentrant manner. The nested call returns `emptyArray` that is a signal for `structuredTypeRelatedToWorker` to return `Ternary.Unknown`.

So `checkTypeArguments` called by `getInstantiatedSignatures` doesn't report an error. In the old version of the code, this would be re-called after the variance worker would completely exit and the error would be raised.

I see 2 ways to solve this:
- ignore the introduced caching based `inVarianceComputation` to avoid spoiling this
- defer `checkTypeArguments` in `getInstantiatedSignatures` (well, call it with `/*reportErrors*/ false` and defer anoher call with `/*reportErrors*/ true`)

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 repro TypeScript Playground được liên kết và theo dõi getInstantiatedSignatures qua checkTypeArguments, structuredTypeRelatedToWorker và đường dẫn inVarianceComputation. So sánh hành vi với liên kết Playground 5.6 và xác định cách phép kiểm tra bị trì hoãn hoặc chưa được lưu vào bộ nhớ đệm cần báo cáo lỗi ràng buộc. Được xem là hoàn tất khi repro hiện tại tạo ra chẩn đoán 2344 mà không làm hỏng hành vi kiểm tra kiểu liên quan.

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
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.