Skip to content

Commit

Permalink
docs: add OneofValue type helper
Browse files Browse the repository at this point in the history
We can't use oneof field directly.

This helper allows for strict type checking and passing oneof fields as an argument

Signed-off-by: clucle <[email protected]>
  • Loading branch information
clucle committed Apr 18, 2024
1 parent 7f36a59 commit c61edef
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,14 @@ type OneOfCase<T, K extends OneOfCases<T>> = T extends {
}
? T[U]
: never;

/** Extracts the specific type of a value type from a oneOf field */
export type OneOfValue<T, K extends OneOfCases<T>> = T extends {
$case: K;
[key: string]: unknown;
}
? T
: never;
```

# Default values and unset fields
Expand Down

0 comments on commit c61edef

Please sign in to comment.