microsoft / microsoft/TypeScript

Confusing diagnostics with exact optional property types (EOPT)

Offen
#56,682 0 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bug Domain: flag: exactOptionalPropertyTypes Help Wanted
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

🔎 Search Terms

EOPT
exact optional property types
exactOptionalPropertyTypes

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about EOPT
⏯ Playground Link

https://www.typescriptlang.org/play?exactOptionalPropertyTypes=true&ts=5.4.0-dev.20231205#code/PTAEAEGcBcCcEsDG0Bco4FcCmAoEEsAPAQ2QHkAHaeAewDtiAbABVhoq1mgE8AVbjpDSZcOHh1ABBUAF5QAb1DEA-GjoYAtgCNOAblBa0MBHQDmAGlAAvVQoC+oO7pw4AZhjrJadUK4AUxGiSAJQKoLBY0BiwPsT6di7+ioGgHgAmWK7wdFhpllZo6ZnZuY7BzviSsKaaWHTQoDSu6AJYoADkyYV0GVk5afHtoPCQoHQ0DcSQkPCmDFqMbdA0oBTEsMQakZyNzeJt7ZJDAO7w0AAWHUSk0JTU9Eys7Jw8-ILCsNjtAHSgAML0GYZWBKNJpbKmDpFPq5IbLdDnJatUZNBFLdamSLtUYUNgcLjwLCQb54MCgJ74ngdLRDEagDQjGZmYY+fYdLqpHrFfqDAwYBoRACOGHgETSLJaEkOPz8ACYAMwAdgAnMEcEA

💻 Code
// @strict: true
// @exactOptionalPropertyTypes: true

type A = { a?: number; b: string, z?: {} };

function f(a: A) { return a; }

f({ a: undefined, z: undefined });
// Argument of type '{ a: undefined; }' is not assignable to parameter of type 'A' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
//  Property 'b' is missing in type '{ a: undefined; }' but required in type 'A'.(2379)

🙁 Actual behavior

Normally nested diagnostic messages are a refinement of their parents. In this case the inner diagnostic about property b is not related to the EOPT assignability issue in the head message. We have two different errors being represented in the same chain.

🙂 Expected behavior

There are several reasonable behaviors here.

  1. Do not change the parent message to the EOPT flavor when the inner message is not EOPT related
  2. Report two separate diagnostics
  3. Display both the current inner message and the EOPT mismatches at the same level

I would prefer option 2.
I have a working version of option 3 that I can a PR for if you want to go that route ( either as a permanent solution or a stop gap until further work on EOPT is done)

Argument of type '{ a: undefined; z: undefined; }' is not assignable to parameter of type 'A'.
  Properties not assignable with exactOptionalPropertyTypes: a, z
  Property 'b' is missing in type '{ a: undefined; z: undefined; }' but required in type 'A'.ts(2345)
Additional information about the issue

No response

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere die Diagnose im verlinkten TypeScript Playground mit aktiviertem strict und exactOptionalPropertyTypes unter Verwendung des bereitgestellten Typs und Aufrufs. Vergleiche die übergeordnete und die verschachtelte Meldung und bestätige mit den Maintainer:innen, ob separate Diagnosen, eine unveränderte übergeordnete Meldung oder die vorgeschlagene Ausgabe auf derselben Ebene gewünscht ist. Als abgeschlossen gilt die Aufgabe, wenn die nicht zusammenhängende Diagnose wegen einer fehlenden Eigenschaft nicht mehr irreführend unter der EOPT-Diagnose verschachtelt ist und eine Abdeckung für dieses Beispiel vorhanden ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.