Skip to content

Udemy/Ts/section7/101: Partial, Readonly type #63

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

Open
wants to merge 49 commits into
base: UdemyTs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
d105911
🌱: README을 수정
4BFC Aug 26, 2024
06270b7
🌱: README을 수정
4BFC Aug 26, 2024
5e69dee
🌱: README을 수정
4BFC Aug 29, 2024
d7c1360
🌱: README을 수정
4BFC Aug 29, 2024
978d932
🌱: README을 수정
4BFC Aug 29, 2024
859bffc
🌱: README을 수정
4BFC Aug 29, 2024
e09d95d
🌱: README을 수정
4BFC Aug 29, 2024
3255009
🌱: README을 수정
4BFC Aug 29, 2024
ab9b8db
🌱: README을 수정
4BFC Aug 29, 2024
5f0f9f9
🌱: README을 수정
4BFC Aug 29, 2024
daaeeed
🌱: README을 수정
4BFC Aug 29, 2024
c8ec455
🌱: README을 수정
4BFC Aug 30, 2024
e2a15fd
🌱: README을 수정
4BFC Aug 30, 2024
61dd842
🌱: README을 수정
4BFC Aug 30, 2024
bce5c89
🌱: README을 수정
4BFC Aug 30, 2024
ed8fa00
🌱: issue templates 생성
4BFC Aug 30, 2024
1559fa2
🌱: pr-template 생성
4BFC Aug 30, 2024
691897a
🌱: pr-template 수정
4BFC Aug 30, 2024
44ec035
🌱: pr-template 수정
4BFC Aug 30, 2024
3c3280b
🚩: udemy section2의 14번 강의를 듣고 실습을 했다.
4BFC Aug 31, 2024
cbf04eb
🔀: Merge branch 'UdemyTs'
4BFC Aug 31, 2024
0f07929
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Aug 31, 2024
757fb99
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Aug 31, 2024
7e8ac7d
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Aug 31, 2024
aa89074
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Sep 1, 2024
79304fe
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Sep 1, 2024
eb21a7f
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Sep 1, 2024
cf56f00
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Sep 1, 2024
7dec10d
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Sep 1, 2024
28200e9
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Sep 1, 2024
621e700
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Sep 2, 2024
5f9833d
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Sep 2, 2024
06d966b
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Sep 20, 2024
571488d
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Oct 1, 2024
467db59
🚩 내장 클래스(제네릭)과 일반 제네릭의 사용 차이
4BFC Oct 1, 2024
74d3e80
🚩: 제네릭 클래스 셜명 주석으로 추가
4BFC Oct 1, 2024
1184460
🐛: 제네릭을 사용하지 않고 객체 타입을 생성하는 방법
4BFC Oct 1, 2024
5f01c18
🐛: 제네릭을 사용하지 않은 방식 추가 설명 주석처리
4BFC Oct 1, 2024
2115458
🚩: ts 엄격 모드 규칙 환경에서의 제네릭 사용 방법과 제네릭의 타입 추론 개념 설명 및 실습
4BFC Oct 1, 2024
c42fca8
🚩: 현재 우리가 설정한 제네릭의 오점을 확인
4BFC Oct 1, 2024
29ea62a
🐛: 우리가 의도한 제네릭의 설정으로 인해 발생한 오류 확인
4BFC Oct 1, 2024
0891a7d
🚩: interface와 Generics의 조합해서 사용하는 방법과 실습
4BFC Oct 1, 2024
5cb0e52
🐛: 반환 값을 명시했을 때 이를 위배하면 발생하는 error 확인
4BFC Oct 1, 2024
88e82b8
🚩: object의 key, value의 값을 컨트롤 할 수 있는 함수 구현 및 실습
4BFC Oct 2, 2024
3093deb
🚩: 객체를 컨트롤 하는 함수에서 age를 추가하고 그 값을 반환하는 실습
4BFC Oct 2, 2024
ad658c3
🚩: class로 구현한 Generics 사용 방법
4BFC Oct 2, 2024
76b4d48
🚩: 코드 동작원리를 완벼하게 파악하지 못했음 따라, issue로 생성해서 추후에 다시 살표볼 코드
4BFC Oct 2, 2024
86069dd
🚩: normal한 방식으로 타입을 정의 하는 방식
4BFC Oct 2, 2024
90ff148
🚩: Partial 타입을 사용하는 방법과 실습 readonly 타입으로 Generic과 함께 사용하는 방법 실습
4BFC Oct 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 11 additions & 30 deletions dist/app.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
"use strict";
var Department = /** @class */ (function () {
// readonly는 프로퍼티를 초기화한 후 수정할 수 없다. 즉, 한번 할당 되면 변경되면 안되는 고유 번호들을 설정할 때 readonly를 사용한다.
function Department(id, name) {
this.id = id;
this.name = name;
// private id: string;
// private name: string;
this.employees = [];
// this.id = id;
// this.name = n
}
Department.prototype.describe = function () {
console.log("Department (".concat(this.id, "): ").concat(this.name));
};
Department.prototype.addEmployee = function (employee) {
// this.id = '2'; // readonly이기 때문에 error가 발생한다.
this.employees.push(employee);
};
Department.prototype.printEmployeeInformation = function () {
console.log(this.employees.length);
console.log(this.employees);
};
return Department;
}());
var accounting = new Department('1', 'Accounting');
accounting.addEmployee('Max');
accounting.addEmployee('Manu');
// accounting.employees[2] = 'Anna';
accounting.describe();
accounting.printEmployeeInformation();
// 제네릭 유틸리티 타입
function createCourseGoal(title, description, date) {
let courseGoal = {};
courseGoal.title = title;
courseGoal.description = description;
courseGoal.completeUntil = date;
return courseGoal;
}
const names = ['Max', 'Anna']; //Readonly 타입으로 제네릭으로 정의
// names.push('Manu'); //readonly 속성으로 push 하거나 pop이 불가능 하다.
// names.pop(); //readonly 속성으로 push 하거나 pop이 불가능 하다.
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>

<body>
<script src="./dist/app.js"></script>
</body>

</html>
98 changes: 20 additions & 78 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,83 +1,25 @@
class Department {
// private id: string;
// private name: string;
private employees: string[] = [];
// readonly는 프로퍼티를 초기화한 후 수정할 수 없다. 즉, 한번 할당 되면 변경되면 안되는 고유 번호들을 설정할 때 readonly를 사용한다.
constructor(private readonly id: string, public name: string) {
// this.id = id;
// this.name = n
}
describe(this: Department) {
console.log(`Department (${this.id}): ${this.name}`);
}
// 제네릭 유틸리티 타입

addEmployee(employee: string) {
// this.id = '2'; // readonly이기 때문에 error가 발생한다.
this.employees.push(employee);
}

printEmployeeInformation() {
console.log(this.employees.length);
console.log(this.employees);
}
// Partial(파셜) 타입
interface CourseGoal {
title: string;
description: string;
completeUntil: Date;
}

class ITDepartment extends Department {
admins: string[];
constructor(id: string, admins: string[]) {
super(id, 'IT');
this.admins = admins;
}
function createCourseGoal(
title: string,
description: string,
date: Date,
): CourseGoal {
let courseGoal: Partial<CourseGoal> = {
};
courseGoal.title = title;
courseGoal.description = description;
courseGoal.completeUntil = date;
return courseGoal as CourseGoal;
}

class AccountingDepartment extends Department {
private lastReport: string;

get mostRecentReport() {
if (this.lastReport) {
return this.lastReport;
}
throw new Error('No report found.');
}

set setMostRecentReport(value: string) {
if (!value) {
throw new Error('Please pass in a valid value!')
}
this.addReport(value);
this.lastReport = value; // 여기서 lastReport를 업데이트 그래야 lastReport가 비어있지 않기 때문에 정상적으로 동작을 한다.
}

constructor(id: string, private reports: string[]) {
super(id, 'Account');
//strictPropertyInitialization 활성화로 초기화 해줘야 함.
this.lastReport = reports[0] || ""; // 초기값을 할당 (reports가 비어있으면 빈 문자열)
}

addReport(text: string) {
this.reports.push(text);
}

printReports() {
console.log(this.reports);
}
}
const accounting = new Department('1', 'Accounting');
const ITaccounting = new ITDepartment('2', ['Max']);

ITaccounting.addEmployee('Max');
ITaccounting.addEmployee('Manu');

// accounting.employees[2] = 'Anna';
ITaccounting.describe();
ITaccounting.printEmployeeInformation();

const NewAccounting = new AccountingDepartment('d2', []);

// console.log(NewAccounting.mostRecentReport); //report가 추가되지 않아서 Error
NewAccounting.setMostRecentReport = 'Year End Report';
NewAccounting.addReport('Something went wrong...');

console.log(NewAccounting.mostRecentReport); //report가 있어서 문제없이 출력

NewAccounting.printReports();
const names: Readonly<string[]> = ['Max', 'Anna']; //Readonly 타입으로 제네릭으로 정의
// names.push('Manu'); //readonly 속성으로 push 하거나 pop이 불가능 하다.
// names.pop(); //readonly 속성으로 push 하거나 pop이 불가능 하다.