본문 바로가기

Uber Eats

# 2-4 TypeScript - class

interface는 js로 컴파일 되지 않는다. 

 

interface 대신에 class를 쓴다. 

 

class Human {
	public name: string;
    public age: number;
    public gender: string;
    constructor(name: stiring, age: number, gender: string) {
    	this.name = string;
    	this.age = number;
    	this.gender = string;
    }
}

const daniel = new Human("Daniel", 30, "male");
const sayHi = (person): string => {
	return `Hello ${person.name}, you are ${person.age}, you are a ${person.gender}!`;
};    

console.log(sayHi(daniel));

export {};

 

index.js에서는 접근 제한자는 없는데  js에서 컴파일 하지 않기 때문이다.

 

github.com/hwan02/typescript