Skip to content

Conversation

azulite
Copy link

@azulite azulite commented Jan 26, 2018

Hello,

I am working on a project with Vue and Typescript. When I try to define multiple endpoints with below code:

const apolloProvider = new VueApollo({
    clients: {
      dev: endpoint1,
      t2: endpoint2,
    },
    defaultClient: endpoint1,
  })

There has TypeScript error that is described at below:

TS2345: Argument of type '{ clients: { dev: ApolloClient<NormalizedCacheObject>; t2: ApolloClient<NormalizedCacheObject>; }...' is not assignable to parameter of type '{ de
faultClient: ApolloClient<{}>; defaultOptions?: VueApolloOptions | undefined; }'.
  Object literal may only specify known properties, and 'clients' does not exist in type '{ defaultClient: ApolloClient<{}>; defaultOptions?: VueApolloOptions | undefined; }'.

[key: string]: any;
install: PluginFunction<{}>;
constructor (options: { defaultClient: ApolloClient<{}>, defaultOptions?: VueApolloOptions });
constructor (options: { defaultClient: ApolloClient<{}>, defaultOptions?: VueApolloOptions, clients: { [key: string]:any } });
Copy link
Contributor

@joe-re joe-re Jan 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@azulite
thanks! this is my mistake 🙇
Client property is optional value, so could you change it to type of optional value?
https://www.typescriptlang.org/docs/handbook/functions.html#optional-and-default-parameters

And I'm glad to run yarn run test:types on your local machine.(Your changes cause to fail tests...)

[key: string]: any;
install: PluginFunction<{}>;
constructor (options: { defaultClient: ApolloClient<{}>, defaultOptions?: VueApolloOptions });
constructor (options: { defaultClient: ApolloClient<{}>, defaultOptions?: VueApolloOptions, clients: { [key: string]:any } });
Copy link
Contributor

@joe-re joe-re Jan 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to use ApolloClient<{}>[] instead of any.

[key: string]: any;
install: PluginFunction<{}>;
constructor (options: { defaultClient: ApolloClient<{}>, defaultOptions?: VueApolloOptions });
constructor (options: { defaultClient: ApolloClient<{}>, defaultOptions?: VueApolloOptions, clients: { [key: string]:any } });
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh yes I should run test and thank you for your suggestions! I am getting myself familiar with TypeScript still, your TS file saved my day 👏

@joe-re
Copy link
Contributor

joe-re commented Jan 31, 2018

@azulite
Cool! It looks good to me.

@Akryum
Could you check it?

@Akryum Akryum merged commit 7be5579 into vuejs:next Feb 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants