microsoft / microsoft/TypeScript
False positive ts(2373)
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 Search Terms
Parameter cannot reference identifier declared after it, ts(2373)
🕗 Version & Regression Information
This is the behavior in every version I tried, and I reviewed the FAQ for entries about anything related (and found nothing).
⏯ Playground Link
💻 Code
/**
* This function throws `ReferenceError: Cannot access 'length' before initialization` at runtime.
*
* TS correctly reports `ts(2373)`. 👍
*/
export const truePositive = <const T>({ [length - 1]: finalItem, length }: readonly T[]): T | undefined => {
return finalItem;
};
/**
* This function works fine at runtime.
*
* TS **in**correctly reports `ts(2373)`. 👎
*/
export const falsePositive = <const T>({ length, [length - 1]: finalItem }: readonly T[]): T | undefined => {
return finalItem;
};
🙁 Actual behavior
A false positive ts(2373) is being reported in a situation where we can determine statically that what the report warns about is not taking place.
Ironically, the false positive ts(2373) might represent a real bug in TS' own modeling of declaration order.
🙂 Expected behavior
No false positive ts(2373) being reported.
Additional information about the issue
To be clear:
In the falsePositive case, we can statically determine that length is declared prior to being used.
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 in TypeScript Playground e confronta i pattern dei parametri di truePositive e falsePositive. Segui l’implementazione della diagnostica ts(2373), quindi aggiungi un test di regressione per il caso di ordine delle dichiarazioni mostrato. Il lavoro è completato quando l’esempio falsePositive non produce alcuna diagnostica, mentre truePositive continua a segnalare il rischio a runtime.
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
- Abbastanza chiara
- Idoneità per principianti
- 35/100