microsoft / microsoft/TypeScript
Object spread works for unconstrained generic
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.4k
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 117
Mô tả
TypeScript Version: 3.8.3
Search Terms:
generic
spread
unrestrained
unrestricted
Expected behavior:
The spread function should not compile because T is not constrained to a type that can be spread.
Actual behavior:
It compiles.
Related Issues:
https://github.com/microsoft/TypeScript/issues/30129
https://github.com/microsoft/TypeScript/pull/13288
Code
function spread<T>(t: T) {
// This should not compile
return { ...t };
}
// The type of `result` is `number` even though the value of `result` is `{}`
const result = spread(5);
Output
"use strict";
function spread(t) {
// This should not compile
return Object.assign({}, t);
}
// Result is still a number when in reality it's {}
const result = spread(5);
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": 2,
"target": "ES2017",
"jsx": "React",
"module": "ESNext"
}
}
Playground Link: Provided
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
Tái hiện hành vi trong liên kết Playground được cung cấp bằng TypeScript 3.8.3 và các tùy chọn trình biên dịch đã liệt kê. Đọc issue và pull request liên quan, sau đó theo dõi cách trình biên dịch xử lý object spread đối với một unconstrained generic. Được xem là hoàn tất khi mẫu bị từ chối như mong đợi và kiểu kết quả không còn giữ nguyên một cách không chính xác là kiểu của đối số.
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