Getting only TID by Entity Query
No. An entity query always returns a list, if you want just one record, you have to get that from the array.

The intval() isn't really necessary though, Drupal/PHP doesn't care if you use the tid as string or integer. Also, it always returns an array, and key() also works on an empty array, so you can really simplify that to just return key($communie);. And I'd actually recommend to use current() or reset() because the key is the revision ID and the value the ID and while terms currently do not yet use revisions, they will likely soon support that. 

So...

$commune = \Drupal::entityQuery('taxonomy_term')
  -&gt;condition('field_zipcode', $postalCode)
  -&gt;condition('vid', 'commune')
  -&gt;execute();

return current($commune);


Is all you need.