FESP02-typescript

멋쟁이 사자처럼 Front-End School Plus 2기: TypeScript 프로그래밍

수업 스케쥴 (일정은 변동 가능)

1주차 (2024.07.01 ~ 2024.07.05, 5일)

2주차 (2024.07.08 ~ 2024.07.12, 5일)

3주차 (2024.07.15 ~ 2024.07.19, 5일)

4주차 (2024.07.22 ~ 2024.07.26, 5일)

5주차 ~ 8주차 (2024.07.29 ~ 2024.08.27, 20일)

개발환경 구축

프로그램 설치

Visual Studio Code 설정

  1. VSCode 실행
  2. File > Preferences > Settings
    • “Files: Auto Save”: onFocusChange
    • “Editor: Font Size”: 각자 조절
    • “Editor: Tab Size”: 2
    • “Editor: Detect Indentation”: 체크 해제
    • “Files: Readonly Include”
      • Add Pattern > workspace-ins/** 입력한 후 OK 선택
      • Add Pattern > sample/** 입력한 후 OK 선택
      • Readonly Include가 보이지 않을 경우 VSCode를 최신 버전(1.79 이상)으로 업데이트
  3. Github 레퍼지토리 복사
    • View > Source Control > Clone Repository 선택
    • https://github.com/uzoolove/FESP02-typescript.git 입력
    • 복사할 적당한 폴더 선택 후 Select as Repository Destination 선택
    • Open 선택

TypeScript Compiler 설치

npm i typescript -g

샘플 코드 복사

터미널 테스트

function hello(name: string): string {
  return 'Hello ' + name;
}
console.log(hello('TypeScript'));
cd workspace/ch01
tsc 01.ts
node 01.js

브라우저 테스트

타입스크립트 설정 파일

tsc –watch 옵션

tsc --watch

웹서버 구동

npx serve .

ESLint

ESLint 설정

npm init -y
npx eslint@latest --init
또는
npm init @eslint/config@latest

Need to install the following packages: @eslint/create-config@1.1.5 Ok to proceed? (y)
  - y
? How would you like to use ESLint?
  - To check syntax and find problems
? What type of modules does your project use?
  - JavaScript modules (import/export)
? Which framework does your project use?
  - None of these
? Does your project use TypeScript?
  - Yes
? Where does your code run?
  - browser
The config that you have selected requires the following dependencies:

eslint@9.x, globals, @eslint/js, typescript-eslint 
? Would you like to install them now?
  - Yes
? Which package manager do you want to use?
  - npm
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";

export default [
  { files: ["**/*.{js,mjs,cjs,ts}"] },
  { languageOptions: { globals: globals.browser } },
  pluginJs.configs.recommended,
  ...tseslint.configs.recommended,
];

설정 파일 내용

커스텀 규칙 설정

export default [
  ......
  {
    "rules": {
      "no-var": "off", // var 키워드 사용 가능
      "prefer-const": "warn", // 변수가 재할당 되지 않는다면 let 대신 const 사용
      "no-cond-assign": "warn", // 조건문에서 변수값 할당식 사용
      "no-redeclare": "warn", // 변수 중복 선언
      "@typescript-eslint/no-unused-vars": "warn", // 사용하지 않는 변수
      "@typescript-eslint/explicit-function-return-type": "off", // 함수의 리턴타입을 명시적으로 지정하지 않아도 됨
      "@typescript-eslint/no-explicit-any": "warn", // any 타입 사용
    }
  }
]

ESLint 실행

VSCode ESLint 플러그인 설치

수업 자료