const value = 'Hallo';
console.log(typeof value);

function printLength(value: string | number) {
  if (typeof value === 'string') {
    console.log(value.length);
  } else {
    console.log(value.toFixed(2));
  }
}

printLength('TypeScript');
printLength(42);

class Animal {}
class Dog extends Animal {}

const dog = new Dog();

console.log(dog instanceof Dog);
console.log(dog instanceof Animal);
console.log(dog instanceof Object);

class Car {
  drive() {
    console.log('Fahren...');
  }
}

class Boat {
  sail() {
    console.log('Segeln...');
  }
}

type Vehicle = Car | Boat;

function move(vehicle: Vehicle) {
  if (vehicle instanceof Car) {
    vehicle.drive();
  } else {
    vehicle.sail();
  }
}

move(new Car());
move(new Boat());

const obj = {
  name: 'John',
};
console.log(typeof obj === 'object');

if (!(obj instanceof Car)) {
  console.log('obj is a car');
}

if ('name' in obj) {
  console.log(obj.name);
}

// console.log('text' instanceof String);
console.log(typeof 'text' === 'string');
