typing을 할 수 있는 방법은 여러가지가 있지만,
노마드코더 수업에서는 interface를 활용해서 정리해보고자 한다.
예시는 Ts Doc에서 가져왔다.
https://www.typescriptlang.org/ko/docs/handbook/2/everyday-types.html#differences-between-type-aliases-and-interfaces
interface Point {
x : number;
y : number;
}
function printCoord(pt: Point) {
console.log("The coordinate's x value is " + pt.x);
console.log("The coordinate's y value is " + pt.y);
}
printCoord({x: 100, y: 100});
printCoord라는 함수에 pt변수를 만들고 직접적으로 :number를 붙이지 않고
interface를 활용했다.
Point라는 객체를 따로 정의해서 연결하였다.
결과는,
노마드코더 참고
#3.2 Typing the Props