Does anyone know how to TypeScript? :joy: `rrdata...
# general
q
Does anyone know how to TypeScript? 😂
rrdatas: [computeInstance.networkInterfaces[0].accessConfigs[0]?.natIp]
I can't seem to get this to work. accessConfigs is an optional, so could be empty
c
TS doesn’t yet have null safe calls. You have to check if it’s defined first I believe.
Is there something special about the export on its own then?
c
Are you getting an actual error, or is your IDE warning you?
q
IDE
I guess I can ignore that and run it ? 😛
c
Right
Obviously you’ll want to fix it though
c
You could add a check above that line to see if
accessConfigs
is
undefined
by doing something like this:
Copy code
if (!computeInstance.networkInterfaces[0].accessConfigs) {
  // Do something when it doesn't have a value. Maybe throw an error?
}
That should get rid of the IDE warning that it could be
undefined
. The other thing you could do is use the assertion operation
!
like this:
computeInstance.networkInterfaces[0].accessConfigs[0]!.natIp
, but this is not really recommended unless you know for sure that it cannot be undefined/null ever.
q
Thanks 🙂