오류&에러/TS

    ts(2345) Argument of type '{ hex: string; }' is not assignable to parameter of type 'Point'.  Type '{ hex: string; }' is missing the following properties from type 'Point': x, yts(2345)

    ts(2345) Argument of type '{ hex: string; }' is not assignable to parameter of type 'Point'. Type '{ hex: string; }' is missing the following properties from type 'Point': x, yts(2345)

    이와 같은 에러도 타입스크립트를 처음 접했을때 충분히 만날수 있는 에러이다. 아니 실무에서도 복잡한 타입을 다룰때는 만날수도 있다. 타입스크립트의 공식문서에 있는 예제를 가져와보겠다. // @errors: 2345 interface Point { x: number; y: number; } function printPoint(p: Point) { console.log(`${p.x}, ${p.y}`); } // ---cut--- const point = { x: 12, y: 26 }; printPoint(point); // prunts "12, 26" const point3 = { x: 12, y: 26, z: 89 }; printPoint(point3); // prints "12, 26" const rec..

    TS2322: Type 'string' is not assignable to type 'number'.

    TS2322: Type 'string' is not assignable to type 'number'.

    TS2322: Type 'string' is not assignable to type 'number'. 타입스크립트를 처음 배울때 만나보는 에러일 확률이 크다. 자바스크립트만 쓰다가 타입스크립트를 쓰게 되면 이런에러를 충분히 만날가능성이 있는데 타입스크립트는 타입을 명시하지 않아도 타입을 추론한다. let a = 5; a = 'hello'; 따라서 이런 코드는 자바스크립트에서는 사용할수 있지만 타입스크립트에서는 불가능하다. a라는 변수에 number 타입인 5를 할당했기때문에 a에는 숫자만 들어갈수 있다. 그럼에도 문자열을 넣으려고 하기때문에 발생하는 에러인 것이다...