microsoft / microsoft/TypeScript
TS2377 not reported when 'super' is called conditionally
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Bug Report
The TS2377 error is reported when the constructor of a derived class does not contain a call to 'super'. However, it is not reported when only some branches contain the call but not others.
🔎 Search Terms
TS2377 super class missing branch
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about Classes
⏯ Playground Link
Playground link with relevant code
💻 Code
class CustomError extends Error {
constructor(value: string | number) {
if (typeof value === 'string') {
super(value)
} else {
// oops, no super() call!
}
}
}
🙁 Actual behavior
TypeScript does not report any errors for the above code.
🙂 Expected behavior
TypeScript should report TS2377 for the above code, since 'super' isn't called in every branch.
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 Playground collegato e conferma la diagnostica TS2377 mancante quando non tutti i rami condizionali chiamano super. Traccia quindi la gestione da parte del compilatore TypeScript dei costruttori delle classi derivate e dei rami del flusso di controllo, poi aggiungi una copertura che mostri che TS2377 viene segnalato a meno che ogni ramo non chiami super.
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
- 48/100