class Shape {
width: number;
height: number;
constructor(width: number, height: number) {
this.width = width;
this.height = height;
}
static checkShape(shape: ShapeType) {
if (shape instanceof Rectangle)
return 'rectangle';
else if (shape instanceof Square)
return 'square';
return 'no valid shape'
}
}
type ShapeType = Rectangle | Shape;
class Square extends Shape {
}
class Rectangle extends Shape {
}
const square = new Square(10, 10);
const rect = new Rectangle(100, 100);
console.log(Shape.checkShape(rect));