microsoft / microsoft/TypeScript
Error from `exactOptionalPropertyTypes` not reported when using object spread with a ternary and optional property acces
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
### 🔎 Search Terms
exactOptionalPropertyTypes
object spread
ternary
### 🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about exactOptionalPropertyTypes, object spread.
### ⏯ Playground Link
https://www.typescriptlang.org/play/?exactOptionalPropertyTypes=true&ts=5.9.3&ssl=5&ssc=32&pln=1&pc=1#code/C4TwDgpgBAYg9nKBeKBvAUFKYCGAnCAO2AEkATAfgC4oBnYPAS0IHN0BfddMiAYwBt80XnEL0oBAI4BXCPQBCcMiBrw4Abi78IwKMHwsdqhJvQB6M3QAWcAO60oEAB6RewCGUd48cPFDKyeogAok44bgDyYMCMojj8AAo+kHigACrgcuj6eIa6KKjYQsTkNFKyCkogAHS4BCWe7KYWUAC2jLS0zCxePn62VkRQ0l2sdGAEOJ44hJ7ueIT4INkGOshoUNVbABQMgRQbdUSkZGUQMnLAisq1xSdQ7FA0qOwAlA-qUC3yAKoA4lwRGJdIUjg0HutypdriBNDk8utCltqrs8PtDndSkV6vdHs83h8sF9LL8AeZLBBvL4oDgwJB8A4RN4+MB+CAoIwAGZQABu8UCHSghDguhw2GSlNANN4vDktA8UE5PlaNMIUDgACMAFYs9BA8Rgk4AJnWAHJTTSHPQmGMAD7DWYQTnMDxw1b5DbI1Ho0GY07Y47kE14tAEproIA
### 💻 Code
```ts
type Foo = {
parentId?: string
}
declare const requestBody: Foo;
let target: Foo;
// shows expected error due to ExactOptionalPropertyTypes
target = { parentId: requestBody.parentId };
// missing error when using spread and ternary
target = { ...(true ? { parentId: requestBody.parentId } : {}) }; // BUG
const { parentId } = requestBody;
target = { ...(true ? { parentId: parentId } : {}) }; // BUG
// error appears correctly if value is not a property accessed from an object
const parentId2 = '' as string | undefined;
target = { ...(true ? { parentId: parentId2 } : {}) };
```
### 🙁 Actual behavior
The expected error is silenced only in the specific case that combines object spread, ternary, and accessing an optional property from an object, although the types are always recognized correctly with `| undefined`.
### 🙂 Expected behavior
All scenarios demonstrated in the code snippet are expected to show the same error.
### Additional information about the issue
_No response_
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
Beginne mit dem verknüpften TypeScript Playground und führe die Reproduktion für exactOptionalPropertyTypes aus. Vergleiche die Fälle mit direkter Zuweisung, Objekt-Spread-Ternär-Ausdruck, destrukturierter Eigenschaft und lokaler Variable; das Issue ist abgeschlossen, wenn die Spread-und-Ternär-Fälle denselben erwarteten Fehler wie die anderen Szenarien melden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100