Unknown
-
[ TypeScript ] TypeScript 의 unknown, void, nerver 타입TIL 2024. 3. 7. 20:39
✅ unknown // unknown type let a : unknown let b = a + 1 //error : a 값이 unknown 이므로 에러 발생 // unknown 상태의 a 값이 number일 경우, string일 경우를 지정해서 해결 if (type of a === "number") { let b = a + 1 } if (type of a === "string") { let b = a.toUpperCase() } ✅ void ( 아무것도 return 하지 않는 함수에서 반환 자료형 ) // void function hello() { console.log("x") } const a = hello() a.toUpperCase() //error : a는 아무것도 return 하지 않는 함수 ..