#3 TypeScript
#3.0 Introduction
TypeScript ใด JS ๊ธฐ๋ฐ์ ์ธ์ด, ๊ฑฐ์ ๋น์ทํจ ใด Strongly Typed Programming Language
=> JS๋ ํ์ ์ ๊ณ ๋ คํ์ง ์์ โ ์์ ์ค์๋ค์ด ๋ฐ์ํด๋ ๊ทธ๋๋ก ์งํ๋จ
โ TypeScript ํ์ ( ํ์ ์ ์ง์ ํด ์ฝ๋ ์คํ ์ ์ฝ๊ฐ์ ๋ณดํธ ์์ฉ )
TS Playground - An online editor for exploring TypeScript and JavaScript
#3.1 DefinitelyTyped
REACT์ ํ์ ์คํฌ๋ฆฝํธ ์ค์น
์ ๋ถ ์ง์ฐ๊ณ ์๋ก ๋ง๋ค๊ธฐ
๋ชจ๋ ํ์ ์คํฌ๋ฆฝํธ ์ค์น
#3.2 Typing the Props
ํ์ ์คํฌ๋ฆฝํธ์ Props ์ค์ ํ๊ธฐ
interface object์ shape๋ฅผ ์ค๋ช
#3.3 Optional Props
๋ชจ๋ Props๋ฅผ ํ์ ์ํ๋ก ๋์ ํ์๊ฐ ์๋ค.
Optional Props๋ฅผ ์ค์ ํ๊ณ ์ถ๋ค๋ฉด interface ๋ด๋ถ props๋ช ๋ค์ ?๋ฅผ ์ถ๊ฐํ๋ค.
ํ์์ธ ๊ฒฝ์ฐ ์ฌ์ฉํ์ง ์๋๋ค๋ฉด ์ด๊น๊ฐ์ ๋ถ์ฌํ ์ ์๋ค.
#3.4 State
๊ธฐ๋ณธ์ ์ธ ์ฌ์ฉ๋ฒ์ ๊ฐ๋ค.
์ด๊น๊ฐ์ ํ์ ๊ณผ ๋ค๋ฅด๋ฉด ์๋ฌ๊ฐ ๋ฐ์ํจ & ์ฌ๋ฌ๊ฐ์ ํ์ ์ ์ค์ ํ ์ ์์
์ด๊น๊ฐ์ ์ฃผ์ง ์์ผ๋ฉด undefined
#3.5 Forms
event ํจ์ ๋ถ๋ถ์์ event์ ํ์ ์ ์ค์ ํ ์ ์์
#3.6 Themes
styled.d.ts ํ์ผ (d.ts โ declaration file)
theme.ts ํ์ผ์ ์ํ๋ ํ ๋ง ์ค์
index.tsx์์ ํ ๋ง๋ฅผ import
app.tsx์์ props๋ก ๋ฐ์ ์ฌ์ฉํ๋ค.
#3.7 Recap
TypeScript ์ ์๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ค๋ฉด npm i โsave-dev @types/styled-components ์ ๊ฐ์ด ํ์ ์คํฌ๋ฆฝํธ์ ๊ทธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ๋ญ์ง ์๋ ค์ฃผ๋ install์ ์ํํด์ผํ๋ค.
SyntheticEvent (ํฉ์ฑ ์ด๋ฒคํธ)
์ด๋ฒคํธ ํธ๋ค๋ฌ๋ ๋ชจ๋ ๋ธ๋ผ์ฐ์ ์์ ๋์ผํ๊ฒ ์ด๋ฒคํธ๋ฅผ ์ฒ๋ฆฌํ๊ธฐ ์ํ Syntetic Event ๊ฐ์ฒด๋ฅผ ์ ๋ฌ๋ฐ๋๋ค.
Keyboard Events ex) onKeyDown onKeyPress onKeyUp
Focus Events ex) onFocus onBlur
Form Events ex) onChange onInput onInvalid onReset onSubmit
Generic Events ex) onError onLoad
etc..
Last updated
Was this helpful?