Apollo-client: [[email protected]] ts use erroring with TS2709

Created on 23 May 2019  路  5Comments  路  Source: apollographql/apollo-client

Intended outcome:
No transitive ts errors

Actual outcome:
Previously working code now errors after updating `[email protected]'

packages/common/node_modules/apollo-cache-inmemory/lib/readFromStore.d.ts:19:20 - error TS2709: Cannot use namespace 'KeyTrie' as a type.

19     cacheKeyRoot?: KeyTrie<object>;

Workaround is to go back to 1.5.1 but I'd rather solve this and get the performance optimization from the good work in #4543

How to reproduce the issue:
Unfortunately I could not reproduce with the unit tests, attempted removing the excludes of test type checking in #4856.

I also tried the simplest bit of code but the following does not reproduce the error (yarn install && yarn test):
https://github.com/rosskevin/apollo-client-cache-inmemory-repro-ts2709

@benjamn I'm not sure what it is specifically that tsc does not like about the code from optimism, but it has failed for me locally in our private app repo with every attempt to rebuild. I tried reproducing for hours the same error inside the repo tests, and altered a few tsconfig settings just to break it but could not reproduce. The code in optimism looks fine, the produced code in the npm package looks fine, yet I'm stuck.

KeyTrie is a class, not a namespace, so not sure if we've bumped into a tsc bug or a code issue.

Any thoughts?

Ultimately this is only in my app, non-reproduced so this issue is going to be closed, but if others run into this also please let me know.

Versions

[email protected]

Most helpful comment

@benjamn I found it!

Self inflicted I'm afraid.

In my list of untyped-modules.d.ts I had listed declare module 'optimism' at some point in the past. This remained and unfortunately took precedence over the packaged files. When I used vscode to go into the def, it went to the appropriate one adding to my confusion.

So, remove declare module 'optimism' got it back to working as it should, as tests already prove works. I'm sorry for the distraction.

All 5 comments

@benjamn I found it!

Self inflicted I'm afraid.

In my list of untyped-modules.d.ts I had listed declare module 'optimism' at some point in the past. This remained and unfortunately took precedence over the packaged files. When I used vscode to go into the def, it went to the appropriate one adding to my confusion.

So, remove declare module 'optimism' got it back to working as it should, as tests already prove works. I'm sorry for the distraction.

Experiencing a similar issue since yesterday:
./node_modules/@wry/context/lib/context.d.ts ERROR in ./node_modules/@wry/context/lib/context.d.ts(6,84): TS2694: Namespace 'NodeJS' has no exported member 'Timeout'.
Seems also to be an issue with a dependency of optimism, workaround is to stick with 1.5.1

@mchong-teal I did see that in my reproduction, you need @types/node added to your project. This def is needed transitively through the updated optimism dependency.

Whew, I have definitely been bitten by old declare module "module-that-used-to-be-commonjs" declarations before. Thanks for digging into this further!

@rosskevin Right, I was using an old version (9.6.40) of @types/node. Updating fixed that issue with 1.6.0.

Was this page helpful?
0 / 5 - 0 ratings