Skip to content

Support exactOptionalPropertyTypes#1371

Open
haines wants to merge 1 commit intobufbuild:mainfrom
haines:exact-optional-property-types
Open

Support exactOptionalPropertyTypes#1371
haines wants to merge 1 commit intobufbuild:mainfrom
haines:exact-optional-property-types

Conversation

@haines
Copy link
Contributor

@haines haines commented Mar 13, 2026

Closes #1358

This PR adds support for the exactOptionalPropertyTypes TypeScript compiler option, which is on by default in tsc --init from Typescript 5.9 onwards. This necessitates adding | undefined to the typing of optional fields so that they may be explicitly set to undefined, not just omitted.

I've enabled the option in the compiler settings for this project to catch any issues, which meant adding a few | undefineds to types used internally as well.

I didn't add it to the JSON types because doing so means either adding | undefined to the fields of JsonObject (which seems wrong when deserializing from JSON can never produce an undefined field) or removing the constraint that MessageJsonType extends JsonValue (which seems wrong because the JSON types are JSON values).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Investigate support for exactOptionalPropertyTypes (on by default from TypeScript 5.9)

1 participant