microsoft / microsoft/TypeScript
Either understand const arrow assertions or give better errors on them
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
As mentioned by @threehams in https://github.com/microsoft/TypeScript/issues/35838#issuecomment-569832017, people are pretty confused about the rules for assertion functions, and I don't blame them. For example
const assert = (blah: unknown): asserts blah => { throw "hai"; }
let x: string | undefined;;
assert(x);
In our nightly releases, we give an elaboration on the declaration of assert like
'assert' needs an explicit type annotation.
For all intents and purposes, it looks like assert does have an annotation! The problem is that assert itself needs a : (x: unknown) => asserts x, because it's not automatically inferred from the arrow function.
We have two options:
-
Remove this restriction when the declaration of an assertion function is trivially detectable.
-
Make assertion function errors more clear for arrow functions:
'assert' needs an explicit type annotation. While the function it has been assigned to is fully annotated, the variable declaration for 'assert' does not.
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
Non è indicato alcun file del repository né alcun test. Riproduci l’esempio di asserzione arrow const dell’issue in una build nightly di TypeScript, quindi esamina il percorso di diagnostica esistente per le funzioni di asserzione. Il lavoro è completato quando le asserzioni arrow banali da rilevare vengono accettate oppure quando la diagnostica spiega che la dichiarazione della variabile stessa è priva dell’annotazione di tipo esplicita richiesta.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100