microsoft / microsoft/TypeScript
The second parameter type of `apply` should be `ArrayLike<T>` instead of `T[]`
- 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
String.prototype.apply
I found #33173, but the issue was closed without a reason. The problem still persists.
### 🕗 Version & Regression Information
At least since v3.3.3 according to the Playground.
### ⏯ Playground Link
https://www.typescriptlang.org/play/?#code/MYewdgzgLgBArgDhgXhmApgdxgVQJZhQICCATqQIYCeAFANoAMAHgCwCMANMywExesBmALoBKANwAoAMpRSBAOYA6AGakQAWwDCACwqlNIACbpFFAA5mANrTBxLljvATigA
### 💻 Code
```ts
const u8 = new Uint8Array([0x41,0x42,0x43]);
String.fromCharCode.apply(null, u8);
```
### 🙁 Actual behavior
```
Argument of type 'Uint8Array' is not assignable to parameter of type 'number[]'.
Type 'Uint8Array' is missing the following properties from type 'number[]': pop, push, concat, shift, and 3 more.(2345)
```
### 🙂 Expected behavior
no error
### Additional information about the issue
This code works fine at runtime. [ECMAScript spec](https://262.ecma-international.org/#sec-function.prototype.apply) does not require a genuine array at all. ArrayLike is sufficient.
Workarounds such as
```ts
String.fromCharCode.apply(null, Array.from(u8));
```
will impose runtime overheads.
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu với reproduction TypeScript Playground được liên kết và kiểm tra khai báo thư viện cho Function.apply, tập trung vào kiểu của tham số thứ hai. Xác nhận rằng khai báo chấp nhận ví dụ Uint8Array mà không có lỗi, đồng thời giữ nguyên hành vi apply hiện 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ó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- 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
- 48/100