Giter Club home page Giter Club logo

draggable's Issues

TS 마이그레이션

기존 리액트 프로젝트에 타입스크립트 도입하기

  1. 타입 스크립트 라이브러리 설치
npm i -D typescript @types/node @types/react @types/react-dom @babel/preset-typescript
  1. 타입스크립트 설정 파일 생성

tsc cli 커맨드 사용을 위해

brew install typescript

타입스크립트 설정 파일 tsconfig.json 생성을 위해

tsc --init
  • tsconfig.json 가 위치하는 곳이 타입스크립트 Root로 취급 됨. root를 기준으로 ./ src/ 을 프로그램에 포함하고 싶기 떄문에 tsconfig에 "include": ["./src/"], 을 추가.
  1. 기존 JSX 파일을 TSX로 변환
  • 기존에 작성한 자바스크립트 파일에는 대부분 타입이 설정되어 있지 않아, noImplicitAny 컴파일 에러가 다수 발생할테니 해당 옵션을 우선 off 해둔다. "noImplicitAny": false
  • tsx 파일의 jsx 문법을 제대로 컴파일 할 수 있도록 jsx 관련 설정을 추가. 이 프로젝트에서는 jsx option 값을 "jsx": "preserve"로 주었음. (TS: JSX config)
  • 기존에 웹팩을 사용하고 있었으므로, ts, tsx 파일을 위한 웹팩 설정을 추가한다.
  • 기존에 바벨을 사용하고 있었으므로, 바벨이 타입스크립트 파일을 잘 트랜스파일링 할 수 있도록 관련 preset을 추가합니다.

webpack.config.js

module: {
        rules: [
        {
            test: /\.(js|jsx|ts|tsx)$/,
            use: ['babel-loader'],
            exclude: /node_modules/,
        }, 
        ...
        ],
    },

.babelrc

{
    "presets": [
        ...,
        "@babel/preset-typescript"
    ]
  
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.