Skip to content

Commit 0f07929

Browse files
committed
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-List/TypeScript into UdemyTs
2 parents cbf04eb + 217ca7b commit 0f07929

File tree

3 files changed

+34
-28
lines changed

3 files changed

+34
-28
lines changed

src/app.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
function add(n1, n2, showResult, phrase) {
2-
if (showResult) {
3-
console.log(n1 + n2);
4-
}
5-
else {
6-
return n1 + n2;
7-
}
8-
}
9-
var number1 = 5;
10-
var number2 = 2.8;
11-
var printResult = true;
12-
var resultPhrase = 'Result is: ';
13-
add(number1, number2, printResult, resultPhrase);
1+
//console.log(person.name); 으로 person.name, 객체 타입으로 접근하기 위한 object 타입 정의 방법
2+
var person = {
3+
name: 'Maximilian',
4+
age: 30
5+
};
6+
console.log(person.name); //error : Object에 name이 없습니다. 그렇다면 어떻게 해야할까?

src/app.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
function add(n1: number, n2: number, showResult: boolean, phrase: string) {
2-
const result = n1 + n2; //result는 number라고 추론을 한다.
3-
if (showResult) {
4-
console.log(result + phrase);
5-
} else {
6-
return n1 + n2;
7-
}
8-
}
1+
//console.log(person.name); 으로 person.name, 객체 타입으로 접근하기 위한 object 타입 정의 방법
2+
const person: {
3+
//entry 추가
4+
//앞서 말했 듯 객체 타입을 정의하기 위해서는 할당 후 `;`를 붙여야 한다.
5+
name: string;
6+
age: number;
7+
// 이렇게 작성을 하게 되면 추후에 정의한 객체 타입을 재활용할 수 있게 된다.
8+
} = { //`{}` 특정 객체 타입을 위한 표기법, 객체의 구조 정보를 제공하는 것. 빈 `{}`으로 할당을 하면 객체로 할당하는 것과 동일시한다.
9+
name: 'Maximilian',
10+
age: 30
11+
};
912

10-
const number1 = 5;
11-
const number2 = 2.8;
12-
const printResult = true;
13-
const resultPhrase = 'Result is: ';
14-
// resultPhrase = 0; //error -> 타입 추론으로 resultPhrase는 string이다. 따라 0이라는 number타입을 할당할 수 없다.
15-
16-
add(number1, number2, printResult, resultPhrase);
13+
console.log(person.name); //error : Object에 name이 없습니다. 그렇다면 어떻게 해야할까?

src/basics.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function add(n1: number, n2: number, showResult: boolean, phrase: string) {
2+
const result = n1 + n2; //result는 number라고 추론을 한다.
3+
if (showResult) {
4+
console.log(result + phrase);
5+
} else {
6+
return n1 + n2;
7+
}
8+
}
9+
10+
const number1 = 5;
11+
const number2 = 2.8;
12+
const printResult = true;
13+
const resultPhrase = 'Result is: ';
14+
// resultPhrase = 0; //error -> 타입 추론으로 resultPhrase는 string이다. 따라 0이라는 number타입을 할당할 수 없다.
15+
16+
add(number1, number2, printResult, resultPhrase);

0 commit comments

Comments
 (0)