codestates / codestates/Lumiere

[에러 핸들링] TypeScript에서 localstorage 불러올때 Type 'null' is not assignable to type 'string'

Open
#283 0 comments 0 reactions 1 assignee Claimed by @developerjhp View on GitHub
Completed Error
Dominant language
TypeScript
Stars
7
Forks
4
PR merge metrics
No merged PRs in 30d

Description

![](https://images.velog.io/images/developerjhp/post/c48cec88-c5ef-421d-82d3-d5469af4ee73/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202021-12-09%20%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE%2011.35.30.png)

```tsx
setIsLiked(
!![res.data][0].artistDetail.likes.find(
(el) =>
el === JSON.parse(localStorage.getItem('lumiereUserInfo'))._id,
),
);
```
위 코드를 아래와 같이 바꾸면 해결된다.

```tsx
setIsLiked(
!![res.data][0].artistDetail.likes.find(
(el) =>
el === JSON.parse(localStorage.getItem('lumiereUserInfo' || '{}'))._id,
),
);
```

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.