-
Notifications
You must be signed in to change notification settings - Fork 22
complete/week1 #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
complete/week1 #13
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,6 +144,8 @@ const palette = { | |
| white: '#FFFFFF', | ||
| } as const; | ||
|
|
||
|
|
||
|
|
||
| const basicColors = { | ||
| black: '#000000', | ||
| white: '#FFFFFF', | ||
|
|
@@ -163,4 +165,27 @@ const basicColors = { | |
| navy: '#000080', | ||
| }; | ||
|
|
||
| const YOURE_PALETTE_THEME = {}; | ||
| type ValueOf<T> = T[keyof T]; | ||
|
Comment on lines
167
to
+168
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😮 오!! 이런 유틸리티 타입을 만드셔서 아래의 상수를 작성해주셨네요! 잘 봤습니다👏 |
||
|
|
||
| type PaletteTheme = { | ||
| [key in keyof typeof basicColors]: ValueOf<typeof palette>; | ||
| } | ||
|
|
||
| const YOURE_PALETTE_THEME: PaletteTheme = { | ||
| black: '#00008B', | ||
| white: '#006400', | ||
| red: '#FFFAF0', | ||
| lime: '#00FF00', | ||
| blue: '#0000FF', | ||
| yellow: '#FFFF00', | ||
| 'cyan/aqua': '#483D8B', | ||
| 'magenta/fuchsia': '#FF00FF', | ||
| silver: '#C0C0C0', | ||
| gray: '#808080', | ||
| maroon: '#800000', | ||
| olive: '#F0FFF0', | ||
| green: '#008000', | ||
| purple: '#FFE4E1', | ||
| teal:'#F0E68C', | ||
| navy: '#F08080', | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| /** | ||
| * 아래의 userRole이 가진 리터럴 타입을 제거하여 UserInformation을 유연하게 만드려면 어떻게 할까요? | ||
| */ | ||
|
|
||
| type UserRole = 'normal' | 'vip' | 'admin' | ||
|
|
||
| type UserInformation = { | ||
| userId: string; | ||
| userName: string; | ||
| userRole: 'normal' | 'vip' | 'admin'; | ||
| userRole: UserRole; | ||
| password: string; | ||
|
Comment on lines
9
to
11
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 리터럴 타입을 타입 별칭으로 분리!! 아주 좋습니다! |
||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,14 +5,22 @@ | |
| * - 특정 index의 원소를 변경하는 update 메서드를 만들어주세요. | ||
| */ | ||
|
|
||
| class List { | ||
| private items: any[] = []; | ||
| class List<T> { | ||
| private items: T[] = []; | ||
|
Comment on lines
+8
to
+9
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
|
||
| add(item: any) { | ||
| add(item: T) { | ||
| this.items.push(item); | ||
| } | ||
|
|
||
| get(index: number) { | ||
| return this.items[index]; | ||
| } | ||
|
|
||
| remove(index: number) { | ||
| return this.items.splice(index, 1); | ||
| } | ||
|
Comment on lines
+19
to
+21
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 제거된 값을 return 해주셨네요! 좋습니다🙌 |
||
|
|
||
| update(index: number, value: T) { | ||
| return this.items[index] = value; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,11 @@ type HumanProps = { | |
| }; | ||
| }; | ||
|
|
||
| const Bob: HumanProps = { | ||
| type DeepReadonly<T> = { | ||
| readonly [key in keyof T]: DeepReadonly<T[key]> | ||
| } | ||
|
Comment on lines
+19
to
+21
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 인덱스 시그니처의 좋은 활용 예죠! 아주 좋습니다🙌 |
||
|
|
||
| const Bob: DeepReadonly<HumanProps> = { | ||
| firstName: 'Bob', | ||
| surname: 'Keel', | ||
| profile: { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,22 +2,18 @@ | |
| * 아래의 코드 중 타입 별칭을 제거하여 동일한 결과를 내도록 작성해주세요. | ||
| */ | ||
|
|
||
| type SavingAction = { | ||
| type: 'saving'; | ||
| payload: string[]; | ||
| type ActionType = 'saved' | 'saving' | ||
| type Action = { | ||
| type: ActionType, | ||
| payload?: string[] | ||
| }; | ||
|
|
||
| const savingAction: SavingAction = { | ||
| const savingAction: Action = { | ||
| type: 'saving', | ||
| payload: ['Apple', 'Banana', 'Strawberry'], | ||
| }; | ||
|
|
||
| type SavedAction = { | ||
| type: 'saved'; | ||
| }; | ||
|
|
||
| const savedAction: SavedAction = { | ||
| const savedAction: Action = { | ||
|
Comment on lines
+11
to
+16
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 타입을 사전에 정의해서 상수를 제한했네요! 좋습니다 ㅎㅎ |
||
| type: 'saved', | ||
| }; | ||
|
|
||
| type Actions = SavingAction | SavedAction; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,9 @@ | |
| * 아래의 코드 중 Cylinder 타입을 유지하기 위한 코드를 작성해주세요. | ||
| */ | ||
|
|
||
| interface Cylinder { | ||
| radius: number; | ||
| height: number; | ||
| class Cylinder { | ||
| radius = 1; | ||
| height = 1; | ||
| } | ||
|
Comment on lines
+5
to
8
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 코드는 아래와 같이 단축된답니다! class Cylinder {
consturctor(public radius:number, public height:number){}
} |
||
|
|
||
| function calculateVolumne(shape: unknown) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /** | ||
| * 아래의 함수가 동작하도록 리팩토링 해주세요. | ||
| * - 문자열 배열을 입력하면 2차원 배열로 각 아이템이 p 태그로 묶여서 나옵니다. | ||
| * [ | ||
| [ | ||
| '<p> 모두 잠드는 밤에 </p>', | ||
| '<p> 혼자 우두커니 앉아 </p>', | ||
| '<p> 다 지나버린 오늘을 </p>', | ||
| '<p> 보내지 못하고서 깨어있어 </p>', | ||
| '<p> 누굴 기다리나 </p>', | ||
| '<p> 아직 할 일이 남아 있었던가 </p>', | ||
| '<p> 그것도 아니면 돌아가고 싶은 </p>', | ||
| '<p> 그리운 자리를 떠올리나 </p>', | ||
| '<p> 무릎을 베고 누우면 나 아주 어릴 적 </p>', | ||
| '<p> 그랬던 것처럼 머리칼을 넘겨줘요 </p>', | ||
| '<p> 그 좋은 손길에 까무룩 잠이 들어도 </p>', | ||
| '<p> 잠시만 그대로 두어요 </p>', | ||
| '<p> 깨우지 말아요 아주 깊은 잠을 잘 거예요 </p>', | ||
| '<p> 조용하던 두 눈을 </p>', | ||
| '<p> 다시 나에게 내리면 </p>', | ||
| '<p> 나 그때처럼 말갛게 </p>', | ||
| '<p> 웃어 보일 수 있을까 </p>', | ||
| '<p> 나 지친 것 같아 </p>', | ||
| '<p> 이 정도면 오래 버틴 것 같아 </p>', | ||
| '<p> 그대 있는 곳에 돌아갈 수 있는 </p>', | ||
| '<p> 지름길이 있다면 좋겠어 </p>', | ||
| '<p> 무릎을 베고 누우면 나 아주 어릴 적 </p>', | ||
| '<p> 그랬던 것처럼 머리칼을 넘겨줘요 </p>', | ||
| '<p> 그 좋은 손길에 까무룩 잠이 들어도 </p>', | ||
| '<p> 잠시만 그대로 두어요 </p>', | ||
| '<p> 깨우지 말아요 아주 깊은 잠을 잘 거예요 </p>', | ||
| '<p> 스르르르륵 스르르 깊은 잠을 잘 거예요 </p>', | ||
| '<p> 스르르르륵 스르르 깊은 잠을 </p>' | ||
| ] | ||
| ] | ||
| * - 함수를 리팩토링해주세요. | ||
| */ | ||
| function parseTaggedText(lines) { | ||
| var paragraphs = []; | ||
| var currPara = []; | ||
| var addParagraph = function (text) { | ||
| currPara.push("<p> " + text + " </p>"); | ||
| }; | ||
| for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) { | ||
| var line = lines_1[_i]; | ||
| addParagraph(line); | ||
| } | ||
| paragraphs.push(currPara); | ||
| return paragraphs; | ||
| } | ||
| var parameter = [ | ||
| '모두 잠드는 밤에', | ||
| '혼자 우두커니 앉아', | ||
| '다 지나버린 오늘을', | ||
| '보내지 못하고서 깨어있어', | ||
| '누굴 기다리나', | ||
| '아직 할 일이 남아 있었던가', | ||
| '그것도 아니면 돌아가고 싶은', | ||
| '그리운 자리를 떠올리나', | ||
| '무릎을 베고 누우면 나 아주 어릴 적', | ||
| '그랬던 것처럼 머리칼을 넘겨줘요', | ||
| '그 좋은 손길에 까무룩 잠이 들어도', | ||
| '잠시만 그대로 두어요', | ||
| '깨우지 말아요 아주 깊은 잠을 잘 거예요', | ||
| '조용하던 두 눈을', | ||
| '다시 나에게 내리면', | ||
| '나 그때처럼 말갛게', | ||
| '웃어 보일 수 있을까', | ||
| '나 지친 것 같아', | ||
| '이 정도면 오래 버틴 것 같아', | ||
| '그대 있는 곳에 돌아갈 수 있는', | ||
| '지름길이 있다면 좋겠어', | ||
| '무릎을 베고 누우면 나 아주 어릴 적', | ||
| '그랬던 것처럼 머리칼을 넘겨줘요', | ||
| '그 좋은 손길에 까무룩 잠이 들어도', | ||
| '잠시만 그대로 두어요', | ||
| '깨우지 말아요 아주 깊은 잠을 잘 거예요', | ||
| '스르르르륵 스르르 깊은 잠을 잘 거예요', | ||
| '스르르르륵 스르르 깊은 잠을', | ||
| ]; | ||
| console.log(parseTaggedText(parameter)); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,13 @@ | |
| * 아래의 함수가 정상적으로 동작하기 위해 어떤 타입을 활용하면 될까요? | ||
| */ | ||
|
|
||
| function prettyPrint(x: any): string { | ||
| type Parameter = string | number | { | ||
| x: Parameter; | ||
| length: number; | ||
| mop: (callback: (x: Parameter)=> string) => string[] | ||
| } | ||
|
|
||
| function prettyPrint(x: Parameter): string { | ||
|
Comment on lines
+5
to
+11
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오....! 타입을 이렇게 프로퍼티로 제한해주셨네요! 정말 신선합니다ㅎㅎ |
||
| if (typeof x === 'string') return `"${x}"`; | ||
|
|
||
| if (typeof x === 'number') return String(x); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,16 @@ | ||
| /** | ||
| * never, unknown, any 타입에 대해 정리하여 최대한 상세하게 적어주세요. | ||
| */ | ||
|
|
||
| const never = ` | ||
| TS에서 가질 수 있는 가장 작은 집합 | ||
| `; | ||
|
|
||
| const unknown = ` | ||
| 모든 타입을 할당 받을 수 있으나 any와 다른 것은 unknown 타입으로 선언된 변수는 any를 제외한 다른 타입으로 선언된 변수에 할당될 수 없다는 것 | ||
| ` | ||
|
|
||
| const any = ` | ||
| 모든 타입을 할당 받을 수 있는 TS의 치트키. | ||
| 하지만 JS프로젝트를 TS로 마이그레이션 할때만 사용하도록 하고 실제 협업에서는 사용을 지양하자. | ||
| ` | ||
|
Comment on lines
+5
to
+16
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 백틱으로 정리!! 이것도 새로운 코드라 재밌었습니다🙌 |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이렇게 유니온이 많거나 객체 형태의 타입은 타입 별칭으로 분리해주는 게 좋죠! 멋있어요😊