Hello World
- typescript 설치
npm install -g typescript - typescript 설치 확인
tsc --version - 프로젝트 생성
npx create-react-app hello-world --typescript - TypeScript 종속성 설치하기
npm install --save-dev typescript @types/react @types/react-dom - App.js 파일을 App.tsx로 변경하기
mv hello-world/src/App.js hello-world/src/App.tsx - tsconfig.json 파일 생성하기
npx tsc --init - tsconfig.json 파일 수정하기
{ "compilerOptions": { "target": "es5", "module": "commonjs", "jsx": "react", "strict": true, "esModuleInterop": true } } - 외부 ts 파일 import
- Student.ts
export class Student { private name : string constructor(name : string) { this.name = name } startRun() { return this.name + "학생은 달리기를 시작했다"; } } - import
import {Student} from './Student';
- Student.ts
- 서버 시작
yarn start