TypeScript

by KirillMetrik

HTML

<div id="app"></div>

CSS

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#app {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  transition: all 0.2s;
  text-align: center;
}

TypeScript

class Animal {
	paws: number;
}

class Human {
  hands: number;
}

function shakeHand(creature: Animal | Person) {
	if(creature instanceof Animal){
      throw Error("I dont't shake paws!")
  }
  document.querySelector("#app").innerHTML="Shaked hands with human.";
}

const animal=new Animal();
const human=new Human();
shakeHand(human);
shakeHand(animal);