Typescript error when compiling a module using apollo-client and apollo-cache-inmemory
See original GitHub issueIntended outcome:
Successful compilation of the project.
Actual outcome:
ERROR in [at-loader] ./node_modules/apollo-cache-inmemory/lib/inMemoryCache.d.ts:5:22
TS2415: Class 'InMemoryCache' incorrectly extends base class 'ApolloCache<NormalizedCacheObject>'.
Types of property 'read' are incompatible.
Type '<T>(query: ReadOptions) => T | null' is not assignable to type '<T>(query: ReadOptions) => T'.
Type 'T | null' is not assignable to type 'T'.
Type 'null' is not assignable to type 'T'.
How to reproduce the issue: tsconfig.json
{
"compilerOptions": {
"sourceMap": true,
"jsx": "preserve",
"target": "es2015",
"lib": ["es2017", "dom", "esnext.asynciterable"],
"module": "es2015",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitThis": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strictNullChecks": true,
"allowSyntheticDefaultImports": false,
"baseUrl": ".",
"paths": {
}
},
"include": [
"src/**/*.ts",
"src/**/*.tsx"
],
"exclude": [
"node_modules"
]
}
Sample module:
import { InMemoryCache } from "apollo-cache-inmemory";
import { ApolloClient, ApolloQueryResult } from "apollo-client";
import { HttpLink } from "apollo-link-http";
import gql from "graphql-tag";
const client = new ApolloClient({
cache: new InMemoryCache() as any,
link: new HttpLink({ uri: process.env.GRAPHQL_ENDPOINT })
});
Version
- apollo-client@2.0.2
- apollo-cache-inmemory@^1.1.0
- apollo-cache@^1.0.0
** Possible cause **
apollo-cache defines ApolloCache
base class with read
method which cannot miss:
abstract read<T>(query: Cache.ReadOptions): T
apollo-cache-inmemory actually has more realistic definition of the return value as T | null
Issue Analytics
- State:
- Created 6 years ago
- Reactions:14
- Comments:22 (2 by maintainers)
Top Results From Across the Web
Migrating to Apollo Client 3.0 - Apollo GraphQL Docs
This article walks you through migrating your application to Apollo Client 3.0 from previous versions of Apollo Client. To illustrate the migration process, ......
Read more >Apollo - React (Typescript) Invariant Error when building ...
I'm struggling with my understanding of all the pieces here. I understand that Invariant Violations are about an issue with the wrong types ......
Read more >Apollo Cache – Angular - GraphQL Code Generator
InMemoryCache is a normalized data store that supports all of Apollo Client 1.0's features without the dependency on Redux. In some instances, ...
Read more >apollo-cache-inmemory - npm
Core abstract of Caching layer for Apollo Client. Latest version: 1.6.6, last published: 3 years ago. Start using apollo-cache-inmemory in ...
Read more >Mike McMann / AngularJS Apollo Client · GitLab
Use your GraphQL server data in your Angular 1.0 app, with the Apollo Client. ... 'apollo-client'; import { InMemoryCache } from 'apollo-cache-inmemory'; ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Am I right to assume that this is still not fixed? I have this code:
and am getting this TS error:
Temporary, and unfortunate, workaround is to set
"strictNullChecks": false
😞