apollographql / graphql-tag

A JavaScript template literal tag that parses GraphQL queries
MIT License
2.32k stars 176 forks source link

Was the d.ts file dropped in v2.12? #742

Closed yuvalhvim closed 1 year ago

yuvalhvim commented 1 year ago

I don't see it, and in our monorepo I always get an older version d.ts, which uses an older version of graphql, which doesn't allow me to upgrade to ApolloServer4

phryneas commented 1 year ago

Could you specify this please? graphql-tag@2.12.6 definitely ships with a lib/index.d.ts

yuvalhvim commented 1 year ago

Ok, I should have definitely elaborated a bit more 😅 We have a monorepo and we're using pnpm. Some projects in the monorepo are using graphql-tag@2.11.0, in which index.d.ts is located right under the root directory of the package under node_modules.

tsc recognizes that index.d.ts to be the correct one, therefore using its import of graphql, which results in types mismatch in our effort to upgrade to ApolloServer4.

To bypass this we're using paths option in tsconfig.json, but maybe moving index.d.ts file to be under the root directory could solve this? Maybe I'm missing the cause of the error entirely? 🤔

phryneas commented 1 year ago

TypeScript should look at the types field in package.json, which is correct.

Your problem here is that TypeScript generally lacks the concept of "two versions of the same library". If those lib versions had slightly different APIs, TypeScript would only ever check for one of them (potentially hiding bugs from you), or even report errors when loading types (if you have skipLibChecks turned on).

You need to make sure that you only have one version of a dependency installed.

phryneas commented 1 year ago

PS: you might be able to achieve this using pnpm.overrides

yuvalhvim commented 1 year ago

Cool, thanks for the answer! I will give it a try :)