I'm getting this error: ERROR TS2322: Type '~lib/@graphprotocol/graph-ts/common/value/Value | null' is not assignable to type '~lib/@graphprotocol/graph-ts/common/value/Value'.

I know it is for this change they made (https://thegraph.com/docs/developer/assemblyscript-migration-guide#nullability-check-with-property-access) but I don't know how to refactor the code to make it work. This is the code I have that gives the error:

  save(): void {
    let id = this.get("id");
    assert(id !== null, "Cannot save Bundle entity without an ID");
      id.kind == ValueKind.STRING,
      "Cannot save Bundle entity with non-string ID. " +
        'Considering using .toHex() to convert the "id" to a string.'
    store.set("Bundle", id.toString(), this);

The specific line is this one:

id.kind == ValueKind.STRING,


3 Answers 3


there are 2 ways to solve this:

  1. in your schema.graphql set kind as optional with a ! at the end
kind: Value!
  1. you check for yor variable ValueKind.STRING to be not null

The snippet that you shared is from generated/schema.ts ?

Hard to say, but the error looks like a type conversion problem. Would need to see your full handler code to give an exact answer, but you can try to use a type cast like as Value.


You can install Graph CLI with either npm or yarn. Copy into your terminal:

npm install -g @graphprotocol/graph-cli


yarn global add @graphprotocol/graph-cli

and make sure you are having typescript version > 2.1

  • 1
    This is almost certainly not the problem Matias is facing. Commented Apr 11, 2022 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.