Skip to content
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

Generating .tsx files will result in broken .d.ts files #612

Open
alber70g opened this issue Dec 10, 2021 · 0 comments
Open

Generating .tsx files will result in broken .d.ts files #612

alber70g opened this issue Dec 10, 2021 · 0 comments

Comments

@alber70g
Copy link

alber70g commented Dec 10, 2021

Reproduce steps

  1. create-react-app with template graphql
  2. add dependencies for @graphql-codegen/typescript-react-query
  3. modify .graphql-let.yml and add schema.graphqls
  4. modify .graphql-let.yml to change typescript-react-apollo to typescript-react-query
  5. run graphql-let

Automated steps

npx create-react-app wrong-dts-react-query --template graphql
cd wrong-dts-react-query
yarn add @graphql-codegen/typescript-react-query
echo "type Query { rates(currency: String!): ExchangeRate!  } type ExchangeRate { currency: String!  rate: Int!	}" >> schema.graphqls
sed -i -e "s/\${REACT_APP_GRAPHQL_ENDPOINT}/schema\.graphqls/" ./.graphql-let.yml
sed -i -e 's/typescript-react-apollo/typescript-react-query/' .graphql-let.yml
./node_modules/.bin/graphql-let

Expected

node_modules/@types/graphql-let/__generated__/src/App-GetRates-Partial.d.ts:21
to contain useQuery-hook types

Actual

export declare const useGetRatesQuery: JSX.Element;

Problem

Using the .tsx instead of .ts, the generation of typescript definitions goes wrong. Typescript thinks this is a JSX.Element because it's written like shown below and in the screenshot

export const useGetRatesQuery = <TData = GetRatesQuery, TError = unknown>(
// etc
)

image

Solution

  1. Change to function instead of lambda
    export const useGetRatesQuery = function <TData = GetRatesQuery, TError = unknown>(
  2. Don't use .tsx but .ts when generics are present.
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

No branches or pull requests

1 participant