https://pulumi.com logo
#general
Title
# general
q

quiet-wolf-18467

09/10/2019, 6:16 PM
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

cool-egg-852

09/10/2019, 7:00 PM
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

cool-egg-852

09/10/2019, 7:03 PM
Are you getting an actual error, or is your IDE warning you?
q

quiet-wolf-18467

09/10/2019, 7:03 PM
IDE
I guess I can ignore that and run it ? 😛
c

cool-egg-852

09/10/2019, 7:03 PM
Right
Obviously you’ll want to fix it though
c

clever-sunset-76585

09/10/2019, 7:22 PM
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

quiet-wolf-18467

09/10/2019, 7:23 PM
Thanks 🙂