Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FE] 존재하지 않는 element에 대한 에러를 출력하는 유틸리티 함수 제작 #150

Merged
merged 5 commits into from
Jul 31, 2024
1 change: 1 addition & 0 deletions frontend/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './date';
export * from './isExistentElement';
18 changes: 18 additions & 0 deletions frontend/src/utils/isExistentElement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
type NullableElement = Element | HTMLElement | null | undefined;

export const isExistentElement = (element: NullableElement, elementName: string): boolean => {
const isExistentElement = element !== null && element !== undefined;
const isHTMLElementOrElement = element instanceof HTMLElement || element instanceof Element;

if (!isExistentElement) {
console.error(`${elementName}을/를 찾을 수 없습니다.`);
return false;
}

if (!isHTMLElementOrElement) {
console.error(`${elementName}은/는 Element 이하의 타입이 아닙니다.`);
return false;
}
Comment on lines +12 to +15
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

존재 여부 뿐만 아니라 Element 이하 타입도 확인해줘서 좀 더 구체적으로 검증하는 것 같아서 좋은 것 같아요!


return true;
};