반응형
Argument of type 'TEmptiable<number>' is not assignable parameter of type 'number' type 'undefined' is not assignable to type 'number'
오류의 핵심은 updatefileGroupid 메서드의 파라미터 타입이 number인데,
filegroupId 변수는 TEmptiable<number> 타입이어서 null이나 undefined일 수도 있기 때문입니다.
즉, number만 받을 수 있는 함수에 number | null | undefined를 넣으니 타입스크립트가 거부하는 거죠.
1. 타입 좁히기 (null/undefined 체크)
if (filegroupId != null) { // null, undefined 둘 다 체크
this.updatefileGroupid(filegroupId);
}
이렇게 하면 함수에는 number만 들어가게 됩니다.
2. 메서드 시그니처 수정
updatefileGroupid가 null 또는 undefined도 받을 수 있게 만들기
updatefileGroupid(fildGroupId: TEmptiable<number>) {
this.fildGroupId = fildGroupId;
}
단, 이렇게 하면 내부에서 null/undefined 처리 로직도 필요합니다.
3. Non-null assertion (!) 사용
filegroupId가 절대 null/undefined가 아닐 거라고 확신할 때
this.updatefileGroupid(filegroupId!);
하지만 이 방법은 런타임에 null/undefined가 들어오면 오류가 납니다. 안전성↓
추천: 데이터가 실제로 항상 존재하는 것이 아니라면
1번 타입 좁히기 방식이 가장 안전합니다.
if (filegroupId != null) {
this.updatefileGroupid(filegroupId);
}
반응형
'React' 카테고리의 다른 글
node 최신 버전 업데이트 방법 (1) | 2025.06.25 |
---|---|
커스터마이징, 혹은 특정 컴포넌트만 사용하고 싶은 경우에 pro-components 패키지를 직접 설치하지 않고 소스 코드를 가져다가 직접 쓰는 방법 (0) | 2025.06.19 |
Ant Design의 전체 아이콘 SVG 소스를 한 번에 추출 하는 방법 (0) | 2025.06.19 |
Java, Spring, iBatis, MariaDB 환경에서 실행 결과를 등록된 수신자들에게 이메일로 발송 예제 (2) | 2025.06.12 |
유효한 Date 객체인지 검사하는 유틸리티 함수 (0) | 2025.06.11 |