'How to handle browser-specific types when used as property types?

Say you have a property like:

public intersectionObserver?: IntersectionObserver;

and you want to use Angular Universal, how do you handle this? With this you only get ReferenceError: IntersectionObserver is not defined.

I know that to check for the platform you can use:

import { isPlatformBrowser, isPlatformServer } from '@angular/common';

...

constructor(@Inject(PLATFORM_ID) private platformId: Object) {}

isBrowser() {
  return isPlatformBrowser(this.platformId);
}

isServer() {
  return isPlatformServer(this.platformId);
}

to handle specific code but I have no idea how to handle properties, nor can I find any resources on the subject which I find bizarre.

How do you handle this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source