microsoft / microsoft/TypeScript
`InstanceType` and constructor return type inference doesn’t work for built‑in subtypes of `ErrorConstructor`
Đang mở
Chưa có ai nhận issue này.
Domain: lib.d.ts
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
- "ErrorConstructor"
- "InstanceType Error"
- "InstanceType ErrorConstructor"
🕗 Version & Regression Information
- This is the behaviour in every version I tried, and I reviewed the FAQ for entries about this.
- I was unable to test this on prior versions because
dtslintonly tests back to TypeScript 5.0, and the bug workbench failed to download versions older than TypeScript 4.0.
⏯ Playground Link
💻 Code
declare class CustomError extends Error {
}
type NE1 = InstanceType<EvalErrorConstructor>;
// ^?
type NE2 = InstanceType<RangeErrorConstructor>;
// ^?
type NE3 = InstanceType<ReferenceErrorConstructor>;
// ^?
type NE4 = InstanceType<SyntaxErrorConstructor>;
// ^?
type NE5 = InstanceType<TypeErrorConstructor>;
// ^?
type NE6 = InstanceType<URIErrorConstructor>;
// ^?
type CE = InstanceType<typeof CustomError>;
// ^?
🙁 Actual behavior
Type query results:
type NE1 = Error
type NE2 = Error
type NE3 = Error
type NE4 = Error
type NE5 = Error
type NE6 = Error
type CE = CustomError
🙂 Expected behavior
Type query results:
type NE1 = EvalError
type NE2 = RangeError
type NE3 = ReferenceError
type NE4 = SyntaxError
type NE5 = TypeError
type NE6 = URIError
type CE = CustomError
Additional information about the issue
Same happens with:
declare function newError<E extends Error>(ctor: new (msg?: string) => E): E;
declare class CustomError extends Error {
}
let ne1 = newError(EvalError);
// ^?
let ne2 = newError(RangeError);
// ^?
let ne3 = newError(ReferenceError);
// ^?
let ne4 = newError(SyntaxError);
// ^?
let ne5 = newError(TypeError);
// ^?
let ne6 = newError(URIError);
// ^?
let ce = newError(CustomError);
// ^?
Related issues
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- 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 Playground được liên kết và kiểm tra cách các kiểu ErrorConstructor tích hợp sẵn tương tác với InstanceType và khai báo generic newError. So sánh các kiểu được suy luận với kết quả mong đợi của EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError và CustomError; được xem là hoàn tất khi các truy vấn kiểu và các lệnh gọi constructor đều giữ nguyên từng subtype cụ thể.
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