Skip to content

Commit

Permalink
ch03-5 은선님 예시코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
becho2 committed Jul 22, 2022
1 parent 0f3cedc commit f86f892
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ch03/src/ch03-5/type-conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

let person: object = {name: "Jack", age: 33};
console.log((<{name: string}>person).name)
// console.log(person.name) // 여전히 에러 (위에서만 일시적 변환)
// console.log(person.name) // 여전히 에러 (위에서만 일시적 변환된 것)
console.log((person as {age: number}).age)

/* 타입단언 type assertion - 자바스크립트의 타입 변환 구문과 구분하기 위해 새로운 용어
* (<타입>객체)
* (객체 as 타입)
*/

interface Person{
name : string
age : number
}
let person2 : Person = {name :'Jack', age :33}
console.log(typeof person2.name)

0 comments on commit f86f892

Please sign in to comment.