1. Today, What I learned?
2. ๐ง useRef()์ focus ๊ด๋ จ ์๋ฌ
2.1. Property 'focus' does not exist on type 'string'
2.2. Object is possibly 'null'
2.3. Type '...' is not assignable to type '....'
2.4. Argument of type '...' is not assignable to parameter of type
2.5. Type 'boolean | undefined' is not assignable to type 'boolean'. Type 'undefined' is not assignable to type 'boolean'.

1. Today, What I learned?
์ผ์ฐจ์ ์ผ๋ก ํฌ๋๋ฆฌ์คํธ๋ฅผ redux-toolkit์ผ๋ก ๋ฆฌํฉํ ๋ง ํ ํ์ ๋ณธ๊ฒฉ์ ์ผ๋ก ํ์
์คํฌ๋ฆฝํธ๋ก ๋ง์ด๊ทธ๋ ์ด์
์ ๋ค์ด๊ฐ๋ฉฐ ๋ง๋๊ฒ ๋ ์ค๋ฅ๋ค์ ๊ธฐ๋กํด๋ณธ๋ค.
์๋ฌ๊ฐ ๊ผฌ๋ฆฌ์ ๊ผฌ๋ฆฌ๋ฅผ ๋ฌผ๊ณ ๋ฐ์ํด์ ๋ชจ๋ ์๋ฌ๊ฐ ์์ ํด๊ฒฐ๋ ๊ฒ์ ์๋๊ณ ํ์ฌ ์งํํ์ด๋ค.. ๐
๋ด์ผ์ฏค์ ๋ค ์์ฑํ๊ธฐ ์์๊น!..
2. ๐ง useRef()์ focus ๊ด๋ จ ์๋ฌ
2.1. Property 'focus' does not exist on type 'string'

Property 'focus' does not exist on type 'string'
useRef()์ ํ์ ์ด ์ ๋๋ก ์ ํด์ ธ์์ง ์์ ๋ฐ์ํ ์๋ฌ..
์ฐพ์๋ณด๋ useRef๋ฅผ DOM ์กฐ์ ์ฉ๋๋ก ์ฌ์ฉํ๋ ค๋ฉด ์๋์ ๊ฐ์ด HTMLํ๊ทธ๋ฅผ ์ง์ ํด์ค์ผ ํ๋ค๊ณ ..
์ง์ญ๋ณ์๋ก useRef๋ฅผ ์ธ ๊ฒฝ์ฐ์๋ string์ด๋, number ๊ฐ์ ์ฐ์์ ํ์ํ ํ์ ์ ๋ฃ์ด์ฃผ๋ฉด ๋๋ค.
const newTitleInput = useRef<HTMLInputElement>(null);
const newContentInput = useRef<HTMLInputElement>(null);
2.2. Object is possibly 'null'

Object is possibly 'null'
๋ค์์ผ๋ก ๋ฐ์ํ ์๋ฌ!.. useRef์ ๊ฐ์ด null์ด ๋ ์๋ ์๋ค๋ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ ์ด์ ๋ํ ์ฒ๋ฆฌ๊ฐ ํ์ํ๋ค.

null ๊ฐ์ผ ์๋ ์๋ค๋ ๋ง์ ์ต์ ๋ ์ฒด์ด๋ ์ฐ์ฐ์๋ก ํด๊ฒฐ!..
const editTodoHandler = () => {
//...
if (!newTitle) {
alert('์ ๋ชฉ์ ์
๋ ฅํด์ฃผ์ธ์.');
newTitleInput?.current?.focus();}
//...
}
2.3. Type '...' is not assignable to type '....'

Type '...' is missing the following properties from type 'HTMLTextAreaElement' : cols, rows, textLength, wrap
๋ญ๊ฐ ํ์ ๊ด๋ จ ๋ฌธ์ ๊ฐ ์๋ชป๋ ๊ฒ ๊ฐ์๋ค. conetentInput์ ref๋ ๋ญ๊ฐ ์ข ๋ฌ๋๋๊ฐ ์ถ์ด์ ๋ง์ฐ์ค๋ฅผ ๋๋ฉด ํ์ ์ถ๋ก ์ด ๊ฐ๋ฅํ๋ค.
HTMLTextAreaElement ํ์ ์ผ๋ก ๋ณ๊ฒฝํ์ฌ ์ ์ฉํด์ฃผ์๋๋ ์ด ๋ถ๋ถ์ ํด๊ฒฐ๋์๋ค.
const newContentInput = useRef<HTMLTextAreaElement>(null);
2.4. Argument of type '...' is not assignable to parameter of type

Argument of type '(props: ThemedStyledProps<Pick<DetailedHTMLProps<HTMLAttributes, HTMLParagraphElement>, "key" | keyof HTMLAttributes<...>> & { ...; } & { ...; }, any>) => boolean' is not assignable to parameter of type
์ด ๋ถ๋ถ์ ์คํ์ผ ์ปดํฌ๋ํธ์์ props์ ๋ฐ๋ผ css๋ฅผ ๋ค๋ฅด๊ฒ ์ ์ฉํ๋ ๋ถ๋ถ์ด๋ค.
๊ธฐ์กด ์ฝ๋๋ ๋๋ณํฉ ์ฐ์ฐ์๋ก ์ ์ฉํ๊ณ ์์๋๋ฐ, ํ์ ์คํฌ๋ฆฝํธ๋ก ๋ณํํ ํ์ ์ ์ฉ์ด ๋์ง ์๋ ๊ฒ ๊ฐ์์ ๊ธฐ์กด ์ฝ๋๋ฅผ ์ผํญ์ฐ์ฐ์๋ก ๋ฐ๊พธ์ด์ฃผ์๋ค.

Text ์ปดํฌ๋ํธ์๋ ์ด๊ธฐ ์ํ๋ฅผ null๋ก ๋ฃ์ด์ฃผ์๋ค.

2.5. Type 'boolean | undefined' is not assignable to type 'boolean'. Type 'undefined' is not assignable to type 'boolean'.
Type 'boolean | undefined' is not assignable to type 'boolean'. Type 'undefined' is not assignable to type 'boolean'.


boolean ํ์ ์ด ์๋ ๊ฒฝ์ฐ์ ๋ํ ํธ๋ค๋ง์ด ํ์ํ๋ค๋ ์๋ฌ๋ค. ๊ฐ์ด undefined์ผ ์ ์์ ๋์ ๋ํด ์ฒ๋ฆฌ๋ฅผ ํด์ฃผ์ด ํด๊ฒฐํ๋ค.
return (
<TodoDetail id={todo?.id ?? '') title={todo?.title ?? ''} content={todo?.content ?? ''} isDone={todo?.isDone ??false} />);
์์ง ํด๊ฒฐํด์ผ ํ ์ค๋ฅ๊ฐ ๋ง์ด ๋จ์์์ง๋ง!..
ํ์ ์คํฌ๋ฆฝํธ์ ํ์ ์ ๋ํ ๊ฐ๊ฐ์ ์กฐ๊ธ์ฉ ์ตํ๋๊ฐ๋ ๊ณผ์ ๊ฐ๋ค!.. ๋์ฒด๋ก null์ด๋ undefined์ผ ๊ฒฝ์ฐ์ ๋ํ ์ฒ๋ฆฌ๋ฅผ ํด์ฃผ๋ ๊ฒ์ด ์ค์ํ๋ค๊ณ ๋๊ผ๋ค. ๐ซ
Comment