var inferredString = "this is a string";
var inferredNumber = 1;
inferredString = inferredNumber; // compile error. type number' is not assignable to type 'string'.
Duck typing
Duck typing : 오리같이 보이고 오리같이 꽥꽥거리면 오리이다. 당연한 소리아냐?
Inferred typing이 object에도 적용되는 것으로 보면 될것 같음.
var complextType = { name : "son", isOld: false };
complextType = { isOld: true, name: "song" }; // ok
complextType = { name: "byun" }; // 속성이 덜 되어있으면 fail
complextType = { isOld: false, name: "park", national: "korea" }; // 속성이 더 추가되어도 fail
Inferred typing
타입스크립트는
처음 사용한 행태를 보고 타입을 추론한다.
Duck typing
Duck typing
: 오리같이 보이고 오리같이 꽥꽥거리면 오리이다. 당연한 소리아냐? Inferred typing이 object에도 적용되는 것으로 보면 될것 같음.