question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cache.identify : Index signature is missing in type

See original GitHub issue

related to

#6083

Intended outcome:

I want to retrieve the Apollo Client cache ID for a particular object.

interface MyMapInterface {
  __typename: "Map";
  id: string;
  width: number;
  height: number;
}

const myMap: MyMapInterface = { __typename: "Map", id: "1", width: 100, height: 100 };

client.cache.identify(myMap);

Actual outcome:

I get the following TS error.

Argument of type 'MyInterface' is not assignable to parameter of type 'StoreObject | Reference'.
  Type 'MyInterface' is not assignable to type 'StoreObject'.
    Index signature is missing in type 'MyInterface'.

How to reproduce the issue:

Playground

Versions

  System:
    OS: Windows 10 10.0.19041
  Binaries:
    Node: 15.5.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - ~\Documents\workspace\GOunite\v3\client\node_modules\.bin\yarn.CMD
    npm: 6.14.10 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 87.0.4280.88
    Edge: Spartan (44.19041.423.0), Chromium (87.0.664.75)
  npmPackages:
    @apollo/client: 3.3.6 => 3.3.6
    @apollo/link-context: 2.0.0-beta.3 => 2.0.0-beta.3
    @apollo/link-error: 2.0.0-beta.3 => 2.0.0-beta.3
    @apollo/link-persisted-queries: 1.0.0-beta.0 => 1.0.0-beta.0
    @apollo/link-ws: 2.0.0-beta.3 => 2.0.0-beta.3
    @apollo/react-testing: 3.1.4 => 3.1.4
    apollo: 2.32.1 => 2.32.1
    apollo-cache-persist: 0.1.1 => 0.1.1
    apollo-upload-client: 14.1.0 => 14.1.0

TS 4.1

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:8
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
rylanccommented, Apr 27, 2021

The same issue exists if the interface passed is generated by the Apollo CLI (e.g. using an object returned in the data of a mutation). For best compatibility between Apollo created tools, it seems like changing the parameter type might be the best fix.

0reactions
PeterDekkerscommented, May 24, 2022

It’s possible to circumvent the issue by using spread syntax.

client.cache.identify({ ...myMap });

Although this could affect performance. Personally I prefer to @ts-ignore the warning.

There is a related issue in the Typescript repo.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript: Index signature is missing in type - Stack Overflow
The problem is that when the type is inferred, then the type of o is: { dic: { a: number, b: number }...
Read more >
Managing objects with unknown structures in TypeScript using ...
We look into various options on how to handle an object that has a structure we don't know. We use index signatures and...
Read more >
Documentation - TypeScript 4.4
TypeScript lets us describe objects where every property has to have a certain type using index signatures. This allows us to use these...
Read more >
Index signature for type 'X' is missing in type 'Y' in TS
The error "Index signature for type is missing in type" occurs when TypeScript doesn't consider a type that uses an index signature and...
Read more >
Common issues and solutions - mypy 0.991 documentation
The # type: ignore comment will only assign the implicit Any type if mypy cannot find information about that particular module. So, if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found