목록JS/TypeScript (11)
바스키아
![](http://i1.daumcdn.net/thumb/C150x150.fwebp.q85/?fname=https://blog.kakaocdn.net/dn/pDQdr/btqygBNz2m7/mu6H5W1vJBvOlsY4iLNxbK/img.png)
Intersection 타입?? 영어가 약하므로 우선 횡단, 교차? 우선 예제로 보자 1 2 3 4 5 6 7 8 9 10 interface User { name: string; } interface Action { do() : void; } function createUserAction(u: User, a: Action) { return { ...u, ...a}; } 우선 두 interface 를 합치는 함수가 있다고 하자. 그럼 저 리턴값에 대한 타입을 정의할때 interface Sum{ name:string; do() : void } 따로 인터페이스를 만들어서 function createUserAction(u: user, a: Action) : Sum{ return {...u, ...a} } 이렇게..
https://typescript-kr.github.io/pages/tsconfig.json.html TypeScript 한글 문서 TypeScript 한글 번역 문서입니다 typescript-kr.github.io https://vomvoru.github.io/blog/tsconfig-compiler-options-kr/
es6에 등장한 class키워드는 함수를통해 만들었던걸 클래스를 통해 특정타입의 객체를 사용할수도 있다. 우선 es6의 class 키워드 예제를 보자 ( 자세한 es6는 따로 정리해놓겠다. ) class Cart { constructor(user) { this.user = user; this.store {}; } put(id, project) { this.store[id] = product; } get(id) { return this.store[id]; } } const cart1 = new Cart({name : 'john'}); const cart2 = new Cart({name : 'jay'}); 사질 자바 하던사람은 굉장히 반가울거 같다는 생각이 든다. 클래스 객체지향에 constructor 생성..
![](http://i1.daumcdn.net/thumb/C150x150.fwebp.q85/?fname=https://blog.kakaocdn.net/dn/bEsCfd/btqxPSwbmY5/syWs24mxivhUuu62KlkSdK/img.png)
Enum 이 뭐냐고 찾아보면 열거형 이러고한다 열거형? 형을 쭉 나열한건가? 기본 구조를 봐보자 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 enum StarbuksGrade{ WELCOME, GREEN, GOLD } function getDicount(v: StarbuksGrade): number { switch(v){ case StarbuksGrade.WELCOME: return 0; case StarbuksGrade.GREEN: return 5; case StarbuksGrade.GOLD: return 10; } } console.log(getDicount(StarbuksGrade.GREEN)); console.log(StarbuksGrade.GREEN); 열거된..
이번 글도 사실 딱히 크게 쓸 내용은 없어.... 전에 배운 타입을 함수에도 적용한다는거지.... 정말 간단한거부터 시작할께 function add(x: number, y: number) : number { return x + y; } const result =add(1, 2); function buildUserinfo(name : string, email: string){ return {name, email}; } const user = buildUserInfo(); add함수를 먼처보면 x 와 y 파라미터에 타입을 지정해주었다. 그리고 파라미터 옆에 : 으로 number타입으로 지정해주었는 --> 함수의 바디를보고 반환되는 값이 number다 라고 :number로 리턴타입을 위와같이 지정해주었다. 만..
![](http://i1.daumcdn.net/thumb/C150x150.fwebp.q85/?fname=https://blog.kakaocdn.net/dn/bEkkCC/btqxRwsfylQ/MsM1DBNk9s30zIeNxmGAAk/img.png)
자바에서 사용하던 인터페이스의 의미와 거의 비슷하다고본다 인터페이스는 변수의 타입으로 사용할 수 있다. 이때 인터페이스를 타입으로 선언한 변수는 해당 인터페이스를 준수하여야 한다. 이것은 새로운 타입을 정의하는 것과 유사하다. // 인터페이스의 정의 interface Todo { id: number; content: string; completed: boolean; } // 변수 todo의 타입으로 Todo 인터페이스를 선언하였다. let todo: Todo; // 변수 todo는 Todo 인터페이스를 준수하여야 한다. todo = { id: 1, content: 'typescript', completed: false }; 자세히 봐볼까? 그리고 꼭 변수만이아니야 인터페이스에 두 메소드를 정의하고 변수를..