microsoft / microsoft/TypeScript
Error from `exactOptionalPropertyTypes` not reported when using object spread with a ternary and optional property acces
Chưa có ai nhận issue này.
- 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
exactOptionalPropertyTypes
object spread
ternary
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about exactOptionalPropertyTypes, object spread.
⏯ Playground Link
💻 Code
type Foo = {
parentId?: string
}
declare const requestBody: Foo;
let target: Foo;
// shows expected error due to ExactOptionalPropertyTypes
target = { parentId: requestBody.parentId };
// missing error when using spread and ternary
target = { ...(true ? { parentId: requestBody.parentId } : {}) }; // BUG
const { parentId } = requestBody;
target = { ...(true ? { parentId: parentId } : {}) }; // BUG
// error appears correctly if value is not a property accessed from an object
const parentId2 = '' as string | undefined;
target = { ...(true ? { parentId: parentId2 } : {}) };
🙁 Actual behavior
The expected error is silenced only in the specific case that combines object spread, ternary, and accessing an optional property from an object, although the types are always recognized correctly with | undefined.
🙂 Expected behavior
All scenarios demonstrated in the code snippet are expected to show the same error.
Additional information about the issue
No response
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 TypeScript Playground được liên kết và chạy bản tái hiện exactOptionalPropertyTypes. So sánh các trường hợp gán trực tiếp, toán tử ba ngôi với object spread, thuộc tính được destructure và biến cục bộ; issue được hoàn tất khi các trường hợp spread và toán tử ba ngôi báo cáo cùng một lỗi như mong đợi với các kịch bản khác.
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
- 45/100