부트캠프교육중301 [TS] class 자바스크립트에서 class Person { // 클래스 로직 constructor() { this.name = name; this.age = age; } } 타입스크립트에서 class Person2 { name: string; age: number; constructor(name: string, age: number){ this.name = name; this.age = age; } } 변수의 접근범위도 지정. (private, public, readonly) class Person2 { private name: string: // class안에서만 쓰겠다 하면 private추가 가능 (변수의 접근범위) public age: number; //그렇지 않으면 기본적으로 public들어간다. readonly.. 2023. 8. 15. [TS] enum enum(이넘) -특정 값들의 집합을 의미하는 자료형 숫자형 이넘 enum Shoes { Nike, Adidas } let myShoes = Shoes.Nike; console.log(myShoes); //0 별도의 숫자를 할당하지 않으면 숫자형 이넘으로 취급을 해서 Shoes.Nike = 0; 이렇게 된다. 그래서 결과적으로 콘솔에 0 찍힌다. Adidas = 1; 만약 Nike =10;이렇게 할당하면 Adidas는 11이 된다. 문자형 이넘 enum Shoes { Nike = '나이키', Adidas = '아디다스' } let myShoes = Shoes.Nike; console.log(myShoes); // '나이키' 예제 enum Answer { Yes = 'Y', No = 'N', } funct.. 2023. 8. 15. [TS] 유니언타입(|)과 인터섹션타입(&) 차이 let seho3: string | number | boolean; let capt: string & number & boolean; interface Developer { name: string; skill: string; } interface Person { name: string; age: number; } function askSomeone(someone: Developer | Person){ someone.name } interface Developer { name: string; skill: string; } interface Person { name: string; age: number; } function askSomeone2 (someone: Developer & Person){ some.. 2023. 8. 15. [TS] 인터섹션 타입 인터섹션 타입 & let capt: string & number & boolean; 이건 and의 의미이다. interface Developer { name: string; skill: string; } interface Person { name: string; age: number; } function askSomeone2 (someone: Developer & Person){ someone.name; someone.skill; someone.age; } askSomeone2({ name: '디벨로퍼', skill: '웹개발', age: 34 }); 2023. 8. 15. 이전 1 ··· 9 10 11 12 13 14 15 ··· 76 다음