DEV Community

Cover image for The lowly Interface
John Peters
John Peters

Posted on

The lowly Interface

We want to hook up window resize events easily. So we create this function.

import { Subject } from 'rxjs';
interface wh {
  width: string;
  height: string;
const sub = new Subject<wh>();
export function _resizeEvent(): Subject<wh> {
  window.addEventListener('resize', (ev) => {
    let window = as Window;
    let ele = window.document.activeElement as HTMLElement;
    let width = ele.offsetWidth.toString();
    let height = ele.offsetHeight.toString();{ width: width, height: height });
  return sub;
Enter fullscreen mode Exit fullscreen mode

To use the code above:

import { _resizeEvent } from './functions/observers';

Enter fullscreen mode Exit fullscreen mode

Intellisense now shows us both properties as we type.

Alt Text

Note that interface definitions, unlike class definitions do not support the new keyword. This is pretty much the only difference between the two.

Top comments (0)