codestates / codestates/BanThing

[Error Handling] TypeScript 작성중 Type 선언 관련 에러

Open
#92 0 comments 0 reactions 1 assignee Claimed by @slight-snow View on GitHub
client error solved
Dominant language
TypeScript
Stars
0
Forks
2
PR merge metrics
No merged PRs in 30d

Description

### 어떤 에러인가요?
- Inroduction 이라는 컴포넌트에 imagePosition, image, title 을 props 로 전달하려는 상황이었습니다.

```javascript

```
- 그러자, Introduction 에 빨간 밑줄이 나타나며 아래와 같은 에러 메세지가 나타났습니다.
```
'Introduction' cannot be used as a JSX component.
Its return type 'Element | undefined' is not a valid JSX element.
Type 'undefined' is not assignable to type 'Element | null'.ts(2786)
```

### 에러 핸들링 방법
- TypeScript 의 작성법을 유의하지 않았기에 발생한 에러였습니다.
```javascript
interface propsType {
imagePosition: string;
image: string;
title: string;
}

export default function Introduction(props: propsType) {
return (
<>
//CODE

)
}
```
- 위의 부분에서 `export default function` 다음에 return 값을 Type 으로 설정해둬야했습니다.
```javascript
export default function Introduction(props: propsType): JSX.Element
```


Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.