📎아이템 38 any 타입은 가능한 한 좁은 범위에서만 사용하기
📍 함수와 관련된 any의 사용법
declare function processBar(b: Bar) {}
const f1 () {
const x = expressionReturnFoo();
processBar(x); // 에러: 'Foo' 형식의 인수는 'Bar' 형식의 매개 변수에 할당될 수 없습니다.
}function f1() {
const x: any = expressionReturnFoo(); // 이렇게 하지 말자.
processBar(x);
}
function f2() {
const x = expressionReturningFoo();
processBar(x as any); // 이게 낫다.
}🔗 함수가 any를 반환하는 경우
🔗 @ts-ignore사용하여 오류 제거하기
📍 객체와 관련한 any의 사용법
📍 요약
Last updated