๋ฐ์ํ
Intro
์๋ ํ์ธ์. TypeScript ํ์ ์คํฌ๋ฆฝํธ์์ ref๋ฅผ ์ฌ์ฉํ์ฌ scrollTop ์์น๋ฅผ ๋ณ๊ฒฝํ๋ ๋์ค ์๋์ ๊ฐ์ ์๋ฌ๊ฐ ๋ฐ์ํ์์ต๋๋ค
someRef?.current?.scrollTop = 0;
TS2779: The left-hand side of an assignment expression may not be an optional property access
Why?
์คํ ์์์ ์ต์ ๋ ์ฒด์ด๋๊ณผ ํ ๋น์ ๊ฐ์ด ์ฌ์ฉํ ์ ์๋ค๊ณ ํฉ๋๋ค.
The following is not supported, although it has some use cases; see Issue #18 for discussion:
optional property assignment: a?.b = c
How to solve the problem
์ฝ๋๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ์์ ํ ๊ฒฐ๊ณผ, ๋ ์ด์ ํด๋น ์๋ฌ๊ฐ ๋ฐ์ํ์ง ์์์ต๋๋ค.
if (someRef?.current?.scrollTop) {
someRef.current.scrollTop = 0;
}
์ด ์ธ์๋ ์๋์ ๊ฐ์ด ์์ ํ์ค ์๋ ์์ต๋๋ค.
if (someRef.current.scrollTop != null) {
someRef.current.scrollTop = 0;
}
https://github.com/tc39/proposal-optional-chaining#not-supported
๋ฐ์ํ