📎아이템 37 공식 명칭에는 상표를 붙이기
📍 예제
🔗 벡터
// 상표를 사용하지 않은 경우
interface Vector2D{
x: number;
y: number;
}
function calculateNorm(p: Vector2D){
return Math.sqrt(p.x * p.x + p.y * p.y);
}
calculateNorm({x: 3, y: 4}); // 결과는 5
const vec3D = {x: 3, y: 4, z: 1};
calculateNorm(vec3D); // 잘못된 입력이 들어갔지만, 결과는 5
🔗 number 타입에 상표 붙이기
📍 요약
Last updated