question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Playground config requires all properties in TypeScript

See original GitHub issue

ApolloServer 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:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:17 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
chenglabscommented, Jan 13, 2019

Something like this…

return new ApolloServer({ playground: {...defaultPlaygroundOptions, settings: { ...defaultPlaygroundOptions.settings, "request.credentials": "include", } },

2reactions
marcospgpcommented, Apr 17, 2019

RecursivePartial looks so obscure and complex that I can’t help but feel there is a simpler alternative. This problem surely demonstrates that 😄

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found