microsoft / microsoft/TypeScript
Either understand const arrow assertions or give better errors on them
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Keine Repository-Datei oder kein Test ist angegeben. Reproduziere das Beispiel für eine const-Pfeilfunktions-Assertion aus dem Issue in einem Nightly-TypeScript-Build und untersuche anschließend den bestehenden Diagnosepfad für Assertion-Funktionen. Als erledigt gilt, dass entweder trivial erkennbare Pfeilfunktions-Assertions akzeptiert werden oder die Diagnose erklärt, dass der Variablendeklaration selbst die erforderliche explizite Typannotation fehlt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100