Flow: Property cannot be assigned on possibly undefined value

Created on 1 May 2017  路  2Comments  路  Source: facebook/flow

Hello,

I get this error: Property cannot be assigned on possibly undefined value. My code looks like this:

const clients = new Map();

if (
  clients.has('clientAddress') && // <- This doesn't helps
  typeof clients.get('clientAddress') !== 'undefined' && // <- This doesn't helps too
  clients.get('clientAddress').hasOwnProperty('lastResponse') // <- call of method `hasOwnProperty` (Method cannot be called on possibly undefined value)
)
  clients.get('clientAddress').lastResponse = 'response'; // <- property `lastResponse` (Property cannot be assigned on possibly undefined value)

Flow: latest
Node.js: latest

question

Most helpful comment

You need to assign clients.get('clientAddress') to variable before checking

All 2 comments

You need to assign clients.get('clientAddress') to variable before checking

@vkurchatkin Thanks!

Was this page helpful?
0 / 5 - 0 ratings