Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,26 +464,25 @@ Protobuf-ES generates the following property:
result:
| { case: "number"; value: number }
| { case: "error"; value: string }
| { case: undefined; value?: undefined } = { case: undefined };
| { case: "" };
```

The entire `oneof` group is turned into an object `result` with two properties:

- `case`: The name of the selected field
- `value`: The value of the selected field

This property is always defined on the message—similar to the way map or repeated fields are always defined. By default,
it's `{case: undefined}`.
This property is always defined on the message—similar to the way map or repeated fields are always defined.

In our example, `result.case` can be either `"number"`, `"error"`, or `undefined`. If a field is selected, the
In our example, `result.case` can be either `"number"`, `"error"`, or `""`. If a field is selected, the
property `result.value` contains the value of the
selected field.

To select a field, simply replace the `result` object:

```typescript
user.result = { case: "number", value: 123 };
user.result = { case: undefined };
user.result = { case: "" };
```

To query a `oneof` group, you can use if blocks:
Expand Down Expand Up @@ -512,8 +511,7 @@ switch statements above tell the compiler the type of the `value` property.

> [!TIP]
>
> This feature requires the TypeScript compiler option `strictNullChecks` to be enabled.
> This option is automatically enabled with the option `strict`. See the [documentation][strictNullChecks] for details.
> Oneof types use an empty-string discriminator for the unset case, and are intended for projects using non-strict null checking.

### Proto2 group fields

Expand Down Expand Up @@ -2865,7 +2863,6 @@ Serialization to JSON and binary is deterministic within a version of protobuf-e
[src/wkt/UninterpretedOption_NamePart]: ./packages/protobuf/src/wkt/gen/google/protobuf/descriptor_pb.ts
[src/wkt/Value]: ./packages/protobuf/src/wkt/gen/google/protobuf/struct_pb.ts
[src/wkt/Version]: ./packages/protobuf/src/wkt/gen/google/protobuf/compiler/plugin_pb.ts
[strictNullChecks]: https://www.typescriptlang.org/tsconfig#strictNullChecks
[Text Encoding API]: https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API
[ts-enums]: https://www.typescriptlang.org/docs/handbook/enums.html
[ts-5.0-enum-overhaul]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-0.html#enum-overhaul
Expand Down
40 changes: 20 additions & 20 deletions packages/bundle-size/src/gen/protobuf-es/google/api/client_pb.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading