microsoft / microsoft/TypeScript

Either understand const arrow assertions or give better errors on them

Aperta
#36,067 2 commenti 27 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Domain: Error Messages Experience Enhancement In Discussion Rescheduled Suggestion
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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. 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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.