Skip to content

[redux-saga-requests-graphql]Argument of type 'TemplateStringsArray' is not assignable to parameter of type 'string'. #309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
frkgrall opened this issue Jan 24, 2020 · 8 comments

Comments

@frkgrall
Copy link
Contributor

Typescript seems to be crying when I try to use "gql" from "redux-saga-requests-graphql"
Can be resolved by adding "TemplateStringsArray" as a possible type for "gql" arguments.
Pull request in progress

btw, your lib rocks

ERROR in /<<workspace>>/actions.tsx(7,15):
7:15 Argument of type 'TemplateStringsArray' is not assignable to parameter of type 'string'.
     5 |   type: anAction,
     6 |   request: {
  >  7 |     query: gql`
       |               ^
     8 |       {
     9 |         a request
@klis87
Copy link
Owner

klis87 commented Jan 30, 2020

Could you please show me full snippet here which breaks types?

below https://github.com/klis87/redux-saga-requests/blob/master/packages/redux-saga-requests-graphql/types/index.d.spec.ts#L7 locally I added:

gql(`
  query{
    obj {
      id
    }
  }
`);

and it works. I just wanna make sure that this is really needed. Then I will merge your PR. Thanks!

@klis87
Copy link
Owner

klis87 commented Jan 30, 2020

Sry my bad, actually bracket is wrong here. I am not sure but probably this should be just TemplateStringsArray, not string | TemplateStringsArray

Please confirm and adjust your PR or give me example when string fits gql

@klis87
Copy link
Owner

klis87 commented Jan 30, 2020

I tried this:

gql`
  query{
    obj {
      id ${'1'} ${2}
    }
  }
`;

I believe the correct type is actually

export const gql: (
  query: TemplateStringsArray,
  ...args: (string | number)[]
) => string;

As some people like to have dynamic queries, even though only static ones are officially recommended

@frkgrall
Copy link
Contributor Author

Sounds good ! I'll fix that

@frkgrall
Copy link
Contributor Author

Are regular strings passing the TemplateStringsArray type ?

@klis87
Copy link
Owner

klis87 commented Jan 30, 2020

I think this wont be possible for gql, because gql function can actually be used only with template literals

So

gql`query`

will work.
gql'query' though is incorrect syntax, if this is what you meant.

klis87 added a commit that referenced this issue Jan 31, 2020
This reverts commit 1843813.
@klis87
Copy link
Owner

klis87 commented Jan 31, 2020

Just merged. The only problem is that PR was to dev, which wont be merged to master soon, as there is huge work to be done before this happens. See #306

If you need this now, pls create PR to master directly

@klis87 klis87 closed this as completed in 1843813 Mar 22, 2020
@klis87
Copy link
Owner

klis87 commented Mar 22, 2020

@fhourdin merged in newest version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants