0

I'm new to typescript and I came across this block of code:

visitFieldDefinition(field) {
    const { resolve = defaultFieldResolver } = field;
   // rest of the code
    ....
  }

I read about destructuring assigment which seems fine. But what does {resolve = defaultFieldResolver} mean here?

Neeraj
  • 2,376
  • 2
  • 24
  • 41
  • 3
    Exactly what the name of the variable hints at: [it's a default value](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Default_values_2). – Bergi Apr 01 '20 at 13:12
  • So `resolve` will take on the value `defaultFieldResolver ` if `field.resolve` is `undefined` or `null` ? – Neeraj Apr 01 '20 at 13:13
  • 1
    Only if it is `undefined` – Bergi Apr 01 '20 at 13:14

1 Answers1

0

This means that resolve will take the value defaultFieldResolver in the case it is undefined in field. Otherwise it will take the value given in field.

JeromeBu
  • 1,099
  • 7
  • 13