microsoft / microsoft/TypeScript
Function body is not checked against assertion signature
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
TypeScript Version: 3.7.0-dev.20191002
Search Terms: assertion signatures, asserts, not checked, unchecked, unsound
Code
function assertIsString(x: number | string): asserts x is string {
}
function test(x: number | string) {
assertIsString(x);
x.toUpperCase();
}
test(4);
Expected behavior:
This incorrect empty implementation of assertIsString should not type check, because there are execution paths through assertIsString that don’t narrow the type of x to string as the type of assertIsString should require.
Actual behavior:
No TS errors. Compiled JS code fails at runtime: TypeError: x.toUpperCase is not a function.
Playground Link: Playground nightly isn’t new enough, but maybe it will be by the time you read this: link.
Related Issues:
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 riproducendo l’esempio TypeScript fornito e ispeziona gli entry point del compilatore responsabili delle assertion signatures e del controllo del corpo delle funzioni; l’issue non indica file sorgente né test. Il lavoro è completato quando l’implementazione vuota di assertIsString viene rifiutata, mentre le implementazioni di asserzione valide continuano a essere accettate, con un regression test che copra l’esempio.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100