Program/React Native

React Native Typescript

하랑파파♡ 2020. 2. 6. 14:05
728x90
반응형
SMALL

#typescript 

- 설치 

npm install typescript @types/react @types/react-native --save-dev 
-> typescript : typescript 라이브러리 
-> @types/react : react의 타입이 정의된 파일 정의 파일 
-> @types/react-native : react-native의 타입이 정의된 파일 정의 파일

- tsconfig.json

-> typescript를 설정하기 위해 tsconfig.json 파일을 프로젝트 root 디렉토리에 생성 
-> tsconfig.json 파일에 아래의 내용을 입력

{ 
    "compilerOptions": { 
        "allowJs": true, 
        "allowSyntheticDefaultImports": true, 
        "esModuleInterop": true, 
        "isolatedModules": true, 
        "jsx": "react", 
        "lib": ["ES6"], 
        "moduleResolution": "node", 
        "noEmit": true, 
        "strict": true, 
        "target": "esnext" 
        } 
    }, 
    "exclude": [ 
        "node_modules", 
        "babel_config", 
        "metro.config.js", 
        "jest.config.js" 
    ] 
}

-> App.js 파일을 App.tsx로 파일 확장자를 변경 
-> App.tsx 파일의 내용을 변경 

interface Props {} 추가 
const App = () => {...}을 const App = ({}: Props) => {...} 
ex) 
interface Props {} 

// const App = () => {...} 
const App = ({}: Props) => {...}
728x90
반응형
LIST

'Program > React Native' 카테고리의 다른 글

React Native 프로젝트 설정 : typescript  (0) 2020.03.05
Props와 State  (0) 2020.02.08
절대경로로 컴포넌트 추가  (0) 2020.02.06
Styled Components  (0) 2020.02.06
Mac에서 React Native 개발환경 만들기  (0) 2020.02.06