Angular Service Worker registration with Promise in environment

Angular 8 projekt. I have Promise in environment file:

export const environment:any = new Promise((resolve, reject) => {
  const xhr = new XMLHttpRequest();
  xhr.open('GET', './assets/env/environment.json');
  xhr.onload = function () {
    if (xhr.status === 200) {
      resolve(JSON.parse(xhr.responseText));
    }
    else {
      reject('Cannot load configuration...');``
    }
  };
  xhr.send();
});

This Promise returns correct value production=false or production=true. At the same time Service Worker register correctly if I put there true or false:

ServiceWorkerModule.register("ngsw-worker.js", {
   enabled: true    // or false
})

Registration doesn’t work if I put enabled: environment.production or even enabled: environment.then(env => env.production).

How can I register Service Worker depend on result of this Promise in environment file?

Source: New feed
Source Url Angular Service Worker registration with Promise in environment