microsoft / microsoft/TypeScript
The second parameter type of `apply` should be `ArrayLike<T>` instead of `T[]`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
### 🔎 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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con la riproduzione collegata di TypeScript Playground e ispeziona la dichiarazione della libreria per Function.apply, concentrandoti sul tipo del secondo parametro. Conferma che la dichiarazione accetti l’esempio Uint8Array senza errori, preservando al contempo il comportamento esistente di apply.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 48/100