microsoft / microsoft/TypeScript
Function expressions widen to `{}` in auto arrays
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 Search Terms
function expression widen widening auto array any empty objecr
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
💻 Code
const arr1 = [];
arr1.push(function () {
return "";
});
arr1;
// ^? const arr1: {}[]
const arr2 = [];
arr2.push(() => {
return "";
});
arr2;
// ^? const arr2: (() => string)[]
🙁 Actual behavior
arr1's type after this .push is {}[]
🙂 Expected behavior
I'd expect the type at both of the checked locations to be the same ((() => string)[])
Additional information about the issue
Likely the difference comes from the fact that the function expression is context-sensitive - maybe this is just a design limitation. However, the same doesn't happen in JS with expando objects (TS playground):
const obj = {}
obj.foo = function () {
return ""
}
const result = obj.foo
// ^? const result: () => string
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 l'esempio collegato di TypeScript Playground e confronta i tipi inferiti di arr1 e arr2 dopo le rispettive chiamate a push. Usa l'esempio aggiuntivo di JavaScript expando-object come punto di confronto; il lavoro è completato quando i casi function-expression e arrow-function hanno tipi degli elementi degli array inferiti coerenti, con una copertura di regressione per il comportamento segnalato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100