Skip to content

Udemy/Ts/section2/19 #23

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 27 commits into from
Aug 31, 2024
Merged
Changes from all commits
Commits
Show all changes
27 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
18ab1fd
🚩: tuple은 유니온 타입으로 되어 있어서 두가지 타입으로 재할당 할 수 있다.
4BFC Aug 31, 2024
03f807b
🐛: tuple이 number와 string으로 구성 되어 있다해서 이와 같이 한 쌍을 구성하면 객체에 접근했을 때 오류가 …
4BFC Aug 31, 2024
2605922
🐛: tuple을 잘못사용하는 예시
4BFC Aug 31, 2024
b4cc88f
🚩: 타입추론방식에서 지정해준 방식으로 타입 객체로 할당했을 때 role은 tuple로 인정하지 않고 유니온 타입 배열로 인…
4BFC Aug 31, 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
29 changes: 15 additions & 14 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
const person = {
const person: {
name: string,
age: number,
hobbies: string[];
role: (number | string)[];
} = {
name: 'Maximilian',
age: 30,
hobbies: ['Sports', 'Cooking']
hobbies: ['Sports', 'Cooking'],
//tuple 튜플은 유니온 타입으로 구성되어 있다.
role: [2, 'author']
};

//유니온으로 구성되어 있기 떄문에 number와 string으로 값을 재할당할 수 있다.
person.role.push('admin'); //push는 튜플에서 허용되는 예외이다. 오류를 잡지 못한다.
person.role[1] = 10; //error -> string을 할당할 수 없다.
person.role = [0, 'admin', 'user']; //이러한 추가 방식도 에러가 발생한다.

let favoriteActivities: string[];
favoriteActivities = ['Sports'];

console.log(person.name);

//hobby: 문자열
for (const hobby of person.hobbies) {
//여기서 hobby는 문자열로 취급이 되고 있다.
//이유는 타입 추론으로 인해서다. person.hobbies는 문자열 배열이라고 인식하고 있기 때문이다.
console.log(hobby);
//하지만 map으로 접근을 하게 되면 error가 발생한다. 이유는 문자열은 map으로 사용할 수 없다.
// console.log(hobby.map(el => console.log(el)));// 만약 사용하고 싶다면 person.hobbies를 다른 변수로 정의하고 map을 사용하면 문제 없이 사용할 수다.
}

//arr: 문자열 배열
let hobby = person.hobbies;
// let arr = person.hobbies;
let arr = hobby;
arr.map(el => console.log(el));
}