모르는 변수의 타입을 묘사해야 할 수도 있다. any 로 해결했었지만 any 는 개체를 통해
전파된다고 했다. 이는 type의 안정성을 해친다.
그거를 조금이나마 해소하고자 unknown type이 나왔다.
아무거다 할당할 수 있지만, 컴파일러가 타입을 추론할 수 있게끔 타입의 유형을 좁히거나,
타입을 확정해주지 않으면 다른 곳에 할당 할 수 없다.
declare const maybe: unknown;
const aNumber: number = maybe; // error.
// type guard
if(maybe === true) {
const aBoolean:boolean = maybe; // ok
//const aString:string = maybe // error!
}
// typeof guard
if(typeof maybe === 'string') {
const aString:string = maybe; // ok
//const aBoolean:boolean = maybe; // error!
}