studye / typescript

타입스크립트는 자바스크립트랑 다른 언어인가요?
7 stars 0 forks source link

[Chapter2] Any types and Explicit casting #2

Open sculove opened 7 years ago

sculove commented 7 years ago

any types

https://github.com/studye/typescript/issues/6 으로 인한 오류를 방지하기 위해서는 에라 모르겠다 any 타입

var complextType: any = { name : "son", isOld: false };
complextType = { isOld: true, name: "song" }; // ok
complextType = { name: "byun" }; // any 니깐 ok
complextType = { isOld: false, name: "park",  national: "korea" }; // any 니깐 ok

형 변환

<타입>변환할변수으로 변환한다. 변환할변수 as 타입으로도 변환이 가능하다.

var complextType = { name : "son", isOld: false };
complextType = { isOld: true, name: "song" }; // ok
complextType = <any>{ name: "byun" }; // any 니깐 ok
complextType = <any>{ isOld: false, name: "park",  national: "korea" }; // any 니깐 ok
complextType = { name: "byun" } as any;  // any 니깐 ok
complextType = { isOld: false, name: "park",  national: "korea" } as any;  // any 니깐 ok