타입스크립트에서 타입 단언을 사용할 때 아래 오류 코드가 출력되는 경우가 있다.
[TS2352] Conversion of type 'A' to type 'B' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
이는 무분별한 타입 단언을 미연에 방지하기 위한 에러 코드로, 에러 문구 그대로 의도가 분명하다면 unknown 경유해서 이중 타입 단언으로 이를 해결할 수 있다.
가장 좋은 방법은 zod, valibot 같은 도구를 사용하여 타입 유효성 검사를 수행한 후 타입 단언 없이 안전하게 사용하는 것이지만, 간단한 프로토타이핑 과정에서는 이중 타입 단언을 사용하는 경우가 꽤 잦다.