Issue
I would like the type ShowOptions
to be "ALL" | "ACTIVE" | "DRAFT"
But instead I'm seeing the error TS2339: Property show does not exist on type
Any ideas how I can extract ShowOptions
? Note that I don't have control over the QueryParameters
type - it's automatically generated from an OpenAPI spec.
// Snippet of generated TypeScript code from an OpenAPI definition - I have no control over this code!
type QueryParameters = {
query?: {
show: "ALL" | "ACTIVE" | "DRAFT";
};
};
type Query = QueryParameters["query"];
type ShowOptions = Query["show"]; // TS2339: Property show does not exist on type
Solution
You'll want to wrap Query
in NonNullable<T>
// Snippet of generated TypeScript code from an OpenAPI definition - I have no control over this code!
type QueryParameters = {
query?: {
show: "ALL" | "ACTIVE" | "DRAFT";
};
};
type Query = QueryParameters["query"];
type ShowOptions = NonNullable<Query>["show"];
Answered By - Daniel A. White
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.