반응형

📝교차 타입

interface Car{
    name: string;
    start(): void;
}

interface Toy{
    name: string;
    color: string;
    price: number
}

const toyCar: Toy & Car = {
    name: "타요",
    start() {},
    color: "blue",
    price: 10000
}

 

📝접근 제한자 - static, public, private, protected (type-script에서만 지원)

class Car {

    static wheels: number = 4; // 전역변수 처리 가능

    //private color: string = "car";
    color: string // default : public
    constructor(color: string) {
        this.color = color;
    }

    start() {
        console.log("start");
    }
}

class BMW extends Car {
    constructor(color: string) {
        super(color);
    }

    showColor() {
        console.log(`super.color : ${super.color}`);
        console.log(`this.color :  ${this.color}`);
    }
}

const bmw = new BMW('red');
bmw.showColor();
// super.color : undefined
// this.color :  red
console.log(`Car.wheels : ${Car.wheels}`); // Car.wheels : 4
반응형