개발/backend(js,ts)
optional chainning 적용 시 리턴값 문제
체인의정석
2021. 7. 29. 15:41
728x90
optional chainning을 적용할 경우 아래와 같이 undeifinded가 계속해서 나오게 된다.
optional chainning에서는 리턴 값이 undefined를 주기 때문에 이를 유의해야한다.
Address {
addressType: 'BIZZ',
department: undefined,
subDepartment: undefined,
streetName: undefined,
buildingNumber: undefined,
buildingName: undefined,
floor: undefined,
postBox: undefined,
room: undefined,
postcode: '06232',
townName: 'Seoul',
townLocationName: undefined,
districtName: undefined,
countrySubDivision: undefined,
addressLine: [ '14 Teheran-ro 4-gil, Gangnam-gu', '12th floor' ],
country: 'KR'
}
따라서 다시 스프레드 함수로 체크하는 방식으로 되돌렸다.
Address {
addressType: 'BIZZ',
postcode: '06232',
townName: 'Seoul',
addressLine: [ '14 Teheran-ro 4-gil, Gangnam-gu', '12th floor' ],
country: 'KR'
}
728x90
반응형