complete/week1 - #13
Conversation
| type Name = string | { first: number, last: string} | ||
| type EventDate = string | Date | null |
There was a problem hiding this comment.
이렇게 유니온이 많거나 객체 형태의 타입은 타입 별칭으로 분리해주는 게 좋죠! 멋있어요😊
|
|
||
| const YOURE_PALETTE_THEME = {}; | ||
| type ValueOf<T> = T[keyof T]; |
There was a problem hiding this comment.
😮 오!! 이런 유틸리티 타입을 만드셔서 아래의 상수를 작성해주셨네요! 잘 봤습니다👏
| userName: string; | ||
| userRole: 'normal' | 'vip' | 'admin'; | ||
| userRole: UserRole; | ||
| password: string; |
There was a problem hiding this comment.
리터럴 타입을 타입 별칭으로 분리!! 아주 좋습니다!
userRole이 유연해지려면.... 제너릭을 활용하면 어떨까요?
| type DeepReadonly<T> = { | ||
| readonly [key in keyof T]: DeepReadonly<T[key]> | ||
| } |
There was a problem hiding this comment.
인덱스 시그니처의 좋은 활용 예죠! 아주 좋습니다🙌
저도 리뷰를 받은 부분인데, 추후에는 고도화를 할 수 있는 부분이 많아요.
null, undefined 같은 타입이 들어오면 readonly가 아니게 되거든요!
| class List<T> { | ||
| private items: T[] = []; |
| remove(index: number) { | ||
| return this.items.splice(index, 1); | ||
| } |
| const savingAction: Action = { | ||
| type: 'saving', | ||
| payload: ['Apple', 'Banana', 'Strawberry'], | ||
| }; | ||
|
|
||
| type SavedAction = { | ||
| type: 'saved'; | ||
| }; | ||
|
|
||
| const savedAction: SavedAction = { | ||
| const savedAction: Action = { |
There was a problem hiding this comment.
타입을 사전에 정의해서 상수를 제한했네요! 좋습니다 ㅎㅎ
문제 의도와는 달랐지만 타입을 정의하는 형태가 보기 좋아요!
| class Cylinder { | ||
| radius = 1; | ||
| height = 1; | ||
| } |
There was a problem hiding this comment.
해당 코드는 아래와 같이 단축된답니다!
class Cylinder {
consturctor(public radius:number, public height:number){}
}| type Parameter = string | number | { | ||
| x: Parameter; | ||
| length: number; | ||
| mop: (callback: (x: Parameter)=> string) => string[] | ||
| } | ||
|
|
||
| function prettyPrint(x: Parameter): string { |
There was a problem hiding this comment.
오....! 타입을 이렇게 프로퍼티로 제한해주셨네요! 정말 신선합니다ㅎㅎ
잘 보고 가요! 다만 객체나 function 타입 등이 들어오면... 어떻게 될까요? 😳
| const never = ` | ||
| TS에서 가질 수 있는 가장 작은 집합 | ||
| `; | ||
|
|
||
| const unknown = ` | ||
| 모든 타입을 할당 받을 수 있으나 any와 다른 것은 unknown 타입으로 선언된 변수는 any를 제외한 다른 타입으로 선언된 변수에 할당될 수 없다는 것 | ||
| ` | ||
|
|
||
| const any = ` | ||
| 모든 타입을 할당 받을 수 있는 TS의 치트키. | ||
| 하지만 JS프로젝트를 TS로 마이그레이션 할때만 사용하도록 하고 실제 협업에서는 사용을 지양하자. | ||
| ` |
There was a problem hiding this comment.
백틱으로 정리!! 이것도 새로운 코드라 재밌었습니다🙌
No description provided.