Playground config requires all properties in TypeScript
See original GitHub issueApolloServer constructor accepts parameter playground?: PlaygroundConfig
where
export type PlaygroundConfig =
| RecursivePartial<PlaygroundRenderPageOptions>
| boolean;
where
type RecursivePartial<T> = {
[P in keyof T]?: T[P] extends (infer U)[]
? RecursivePartial<U>[]
: T[P] extends object ? RecursivePartial<T[P]> : T[P]
};
This results in TypeScript requiring one to define all playground options not just the ones that you want to override from defaults.
To reproduce just attempt to create an instance of ApolloServer with playground options not setting all available options:
const server = new ApolloServer({
playground: {
settings: {
"request.credentials": "include",
},
}
});
Failure to provide all options results in:
Types of property 'settings' are incompatible.
Argument of type '{ playground: { settings: { "request.credentials": string; }; }; }' is not assignable to parameter of type 'Config'.
Types of property 'playground' are incompatible.
Type '{ settings: { "request.credentials": string; }; }' is not assignable to type 'boolean | RecursivePartial<RenderPageOptions> | undefined'.
Type '{ settings: { "request.credentials": string; }; }' is not assignable to type 'RecursivePartial<RenderPageOptions>'.
Types of property 'settings' are incompatible.
Type '{ "request.credentials": string; }' is not assignable to type 'ISettings'.
Property ''general.betaUpdates'' is missing in type '{ "request.credentials": string; }'.
TypeScript version: 3.0.3
.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:17 (2 by maintainers)
Top Results From Across the Web
typescript interface require one of two properties to exist
The caveat with RequireOnlyOne is that TypeScript doesn't always know at compile time every property that will exist at runtime.
Read more >Playground Example - Built-in Utility Types - TypeScript
Creates a type which uses the list of properties from KeysFrom and gives them ... Creates a type which converts all optional properties...
Read more >Documentation - Utility Types - TypeScript
Constructs a type with all properties of Type set to optional. This utility will return a type that represents all subsets of a...
Read more >Documentation - Mapped Types - TypeScript
In this example, OptionsFlags will take all the properties from the type Type and change their values to be a boolean.
Read more >Playground Example - Exact Optional Properties - TypeScript
Exact Optional Properties ... For example, this interface declares that there is a property which can be one ... All the configuration options...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Something like this…
return new ApolloServer({ playground: {...defaultPlaygroundOptions, settings: { ...defaultPlaygroundOptions.settings, "request.credentials": "include", } },
RecursivePartial
looks so obscure and complex that I can’t help but feel there is a simpler alternative. This problem surely demonstrates that 😄