microsoft / microsoft/TypeScript
The second parameter type of `apply` should be `ArrayLike<T>` instead of `T[]`
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
### 🔎 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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground の再現例から始め、Function.apply のライブラリ宣言を調べ、2 番目のパラメーターの型に注目してください。宣言が Uint8Array の例をエラーなしで受け入れ、既存の apply の動作を維持していることを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 48/100