microsoft / microsoft/TypeScript
Surprising `Not all code paths return a value`
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
TypeScript Version: 2.5.2
Code
type AsyncFunction<T> = () => Promise<T>;
const f: AsyncFunction<number | void> = async () => {
if (Math.random()) {
return 1;
}
};
Expected behavior:
No tsc errors.
Actual behavior:
const f: AsyncFunction<number | void> = async () => {
// ~~~~~~~~~~~~~ [ts] Not all code paths return a value.
if (Math.random()) {
return 1;
}
};
Notably, when using return-type annotation, this error does not occur:
async function a(): Promise<number | void> {
if (Math.random()) {
return 1;
}
}
const b = async (): Promise<number | void> => {
if (Math.random()) {
return 1;
}
};
In our real-world scenario, it would not be sufficient to look for this syntactic pattern. Rather, the fact that the async function is assigned to a union containing void should be the trigger that silences this error.
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
Riproduci gli esempi di TypeScript 2.5.2 con tsc, confrontando la funzione freccia asincrona assegnata a AsyncFunction<number | void> con le funzioni annotate esplicitamente. Il lavoro è completato quando l’unione contenente void sopprime la diagnostica imprevista, mentre il compilatore continua a segnalare i percorsi di ritorno realmente incompleti.
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