1. Today, What I learned?
2. ํจํค์ง ์ค์นํ๊ธฐ
3. tsconfig.json ํ์ผ ์ค์ ํ๊ธฐ
4. ํ์ผ ์์
5. ๐ง TypeScript์์ styled-components ์ ์ฉ
6. ๐ง tsconfig์ "jsx" ์ค์ ์ถ๊ฐ
6.1. ์ฐธ๊ณ ๊ธ

1. Today, What I learned?
๊ธฐ์กด ํ๋ก์ ํธ์ ํ์ ์คํฌ๋ฆฝํธ ๋ฆฌํฉํ ๋ง์ ์๋ํ๊ธฐ ์์, ํผ์ ํ๋ ํฌ๋๋ฆฌ์คํธ ํ๋ก์ ํธ๋ฅผ ํ์ ์คํฌ๋ฆฝํธ๋ก ๋ฆฌํฉํ ๋ง ํด๋ณด๊ธฐ๋ก ํ๋ค.
๋จผ์ ๊ธฐ์กด ํ๋ก์ ํธ๋ ๋ฆฌ๋์ค์ ๋ผ์ฐํฐ๋ฅผ ์ด์ฉํด์ ํ์ด์ง ์ด๋๊ณผ CRUD๊ฐ ์ ์ฉ๋์ด ์๋ ํฌ๋๋ฆฌ์คํธ์๋ค.
๊ธฐ๋ณธ ๋ฆฌ๋์ค๊ฐ ์ ์ฉ๋์ด ์์๊ธฐ ๋๋ฌธ์ ๋จผ์ redux-toolkit์ผ๋ก ๋ฆฌํฉํ ๋ง ํด์ค ํ ๋ณธ๊ฒฉ์ ์ธ ํ์ ์คํฌ๋ฆฝํธ ์ ์ฉ ์์!..
2. ํจํค์ง ์ค์นํ๊ธฐ
๋จผ์ ํ์ ์คํฌ๋ฆฝํธ์ ๊ด๋ จ๋ ํจํค์ง๋ค์ ์ค์นํด ์ฃผ์๋ค.
ํ์ ์คํฌ๋ฆฝํธ ๊ณต์๋ฌธ์์์ ๋ณด๊ณ ํจํค์ง๋ฅผ ์ค์นํ ํ์,
https://www.typescriptlang.org/download
How to set up TypeScript
Add TypeScript to your project, or install TypeScript globally
www.typescriptlang.org
@types ๊ด๋ จ ํจํค์ง๋ค์ ์ค์นํด์ฃผ์๋๋ฐ ์ด ํ๋ก์ ํธ๋ yarn ํจํค์ง๋ก ๋ง๋ ํ๋ก์ ํธ๋ผ ์๋์ ๊ฐ์ด ์์ฑํ๋ค.
$ yarn add typescript @types/node @types/react @types/react-dom @types/jest --dev

3. tsconfig.json ํ์ผ ์ค์ ํ๊ธฐ
init์ผ๋ก ์ด๊ธฐํ ํ ํ์ผ์์
$ tsc --init
๋ ๊ฐ์ง ์ต์ ์ ๋๋ง ์ฃผ์์ ํด์ ์์ผฐ๋ค.

- noImplicitAny : any๋ผ๋ ํ์ ์ด ์๋์น ์๊ฒ ๋ฐ์ํ ๋ ์๋ฌ ๋์
- strictNullChecks : null, undefined ๋ฑ ์กฐ์ํ๋ฉด ์๋ฌ ๋์
4. ํ์ผ ์์
.js๋ .jsx ํ์ผ์ .ts , .tsx ํ์ผ๋ก ํ์ฅ์๋ฅผ ๋ฐ๊ฟ์ฃผ๊ณ ํ์ ๋ค์ ๋ฃ์ด์ฃผ๋ฉด ๋๋๋ฐ...
๋ณธ๊ฒฉ์ ์ธ ์๋ฌ์ ์์..
5. ๐ง TypeScript์์ styled-components ์ ์ฉ


์ฒ์๋ถํฐ ๋ํญ ๋ฐ์!....
ts๋ก ํ์ผ์ ๋ณํํ๋ styled-componets import ์ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋๋ฐ ๊ด๋ จ ํจํค์ง๋ฅผ ์ถ๊ฐ ์ค์นํด ์ฃผ๋ ํด๊ฒฐ๋์๋ค.
yarn add --dev @types/styled-components
์ด๋ฐ ์์ผ๋ก ํจํค์ง๋ฅผ ๋ช ๊ฐ ์ถ๊ฐํด์ค์ผ ํ๋ ์ผ์ด ์์๋ค.

6. ๐ง tsconfig์ "jsx" ์ค์ ์ถ๊ฐ
'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.
์ต์์ ๋จ์ react๋ฅผ import ํด์ฃผ๋ฉด ๋๋ ์๋ฌ๋ผ๋๋ฐ, tsconfig์ jsx ์ค์ ๋ง ๋ฃ์ด์ค๋ ํด๊ฒฐํ ์ ์์๋ค.

Are you rendering any jsx in the file? If so, you do need to import React, since those jsx tags compile into calls to React.createElement(). Without the import, the references to React are trying to reference a global variable, which then results in that error.
If you're using eslint, i'd recommend using eslint-plugin-react and turning on the rule react-in-jsx-scope, which will catch this case.
jsx์์ ๋ ๋๋ง ํ ๋ React.createElement() ํธ์ถ์ด ํ์ํ๋ฐ, import๊ฐ ์๋ค๋ฉด ๋ฆฌ์กํธ๋ ์ ์ญ๋ณ์์์ ์ด ํธ์ถ์ ํ๋ ค๊ณ ํ๊ธฐ ๋๋ฌธ์ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค๋ ๋ด์ฉ ๊ฐ๋ค.
์ด ์ธ์๋ ๋ง์ ์๋ฌ๊ฐ ๋ ๋ฐ๊ธฐ๊ณ ์์ง๋ง ์ฐจ๊ทผ์ฐจ๊ทผ ํด๊ฒฐํด๋๊ฐ ๋ณด๋๋ก ํ์ ๐..
6.1. ์ฐธ๊ณ ๊ธ
Javascript โ React + TypeScript: โReactโ refers to a UMD global but the current file is a module. Consider adding an impor
We are using React and TypeScript in our current project and I come across below behavior. import React, { Component } from 'react'; I replace the above line with the one below since it seems to be using Component import only. import { Component } from 're
itecnote.com
Comment