Skip to content

Udemy/Ts/section2/21 #25

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

Merged
merged 26 commits into from
Sep 1, 2024
Merged
Changes from all commits
Commits
Show all changes
26 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
b766998
🚩: any타입을 학습하고 실습했다.
4BFC Sep 1, 2024
234f8d9
Merge branch 'UdemyTs' into Udemy/Ts/section2/21
4BFC Sep 1, 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
39 changes: 19 additions & 20 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
// const ADMIN = 0;
// const READ_ONLY = 1;
// const AUTHOR = 2;

enum Role {
ADMIN = 5, READ_ONLY = 'READ_ONLY', AUTHOR = 100 //이후로는 +1씩 증가를 한다.
};

const person = {
const person: {
name: string,
age: number,
hobbies: string[];
role: (number | string)[];
} = {
name: 'Maximilian',
age: 30,
hobbies: ['Sports', 'Cooking'],
role: Role.ADMIN, //0
role: [2, 'author']
};

// person.role = Role.READ_ONLY;
// error -> error TS2367: This comparison appears to be unintentional because the types 'Role.READ_ONLY' and 'Role.ADMIN' have no overlap.
// 원인 : person.role이 Role.READ_ONLY로 설정된 후, TypeScript는 person.role이 더 이상 Role.ADMIN과 같은 값이 될 수 없다고 판단하는 것
person.role.push('admin');
person.role[1] = 10;
person.role = [0, 'admin', 'user'];

//any는 어떤 타입이든 허용하는 타입이다. 어떻게 보면 유연하다고 느껴지질지 모르겠지만 타입스크립트의 장점을 전혀 활용하지 못하기에 좋은 방법은 아니다.
let favoriteActivities: any[];
favoriteActivities = ['Sports', 1]; //이렇게 배열에 마구잡이로 서로 다른 타입을 넣어도 아무런 에러가 일어나지 않는다.

console.log(person.name);

if (person.role === Role.ADMIN) {
console.log(person.role);
} else if (person.role === Role.READ_ONLY) {
console.log(person.role);
} else if (person.role === Role.AUTHOR) {
console.log(person.role);
}
for (const hobby of person.hobbies) {
console.log(hobby);
}