[Typescript 개념 정리 - 2]

Jayden ·2022년 11월 23일
0

1. tsconfig schema

http://json.schemastore.org/tsconfig

  • complie
  • extends
    : TypeScript 2.1 New spec

//base.json
{
  "complierOptions" : {
   	"strict" : true 
  }
  
}

//tsconfig.json
{
	  "extends" : "./base.json"
  	  ...	
}
      
//test.ts
      
const a : number = undefined //extends 주석처리시
      
const a : number = undefined //오류 발생      

//어떤 설정으로 컴파일 할 것인가

  • complileOptions

    • true/ false (default false)
    • atom-typescript 플러그인 설치시
{
 	"conmplieOnSave" : "true" 
}

//어떤 파일을 컴파일 할 것인가

  • file / include / exclude

    • 셋 다 설정이 없으면, 전부 컴파일
  • files

    • 상태 혹은 저절대 경로의 리스트 배열
    • exclude보다 강력
  • include

    • glob 패턴 (마치 .gitignore)
    • * 같은걸 사용하면, .ts / .tsx/ .d.ts 만 include(allowJS)
  • exclude

    • 설정하지 않을 경우 4가지(node_module, bower_components, jspm_package, )을 defalut로 제외
      -은항상 제외합니다.(include에 있어도)
  • compileOption : typeRoots / types

 
 "typeRoots": {
	"description": "Specify multiple folders that act like `./node_modules/@types`.",
	"type": "array",
 	"uniqueItems": true,
 	"items": {
 	"type": "string"
 },
 	"markdownDescription": "Specify multiple folders that act like `./node_modules/@types`.\n\nSee more:
https://www.typescriptlang.org/tsconfig#typeRoots"
 },
 	"types": {
 	"description": "Specify type package names to be included without being referenced in a source
file.",
 	"type": "array",
 	"uniqueItems": true,
 	"items": {
 	"type": "string"
 },
 "markdownDescription": "Specify type package names to be included without being referenced in a
source file.\n\nSee more: https://www.typescriptlang.org/tsconfig#types"
 },
 ...,
}

@types
TypeScript 2.0 부터 사용 가능해진 내장 type definition 시스템
아무 설정을 하지 않을 경우

  • node_modules/@types 라는 모든 경로를 찾아서 사용
  • typeRoots 를 사용하면 배열 안에 들어있는 경로들 아래서만 가져옵니다.
  • types 를 사용하면 배열 안의 모듈 혹은 ./node_modules/@types/ 안의 모듈 이름에서 찾
    아옴
  • [] 빈 배열을 넣으면 이 시스템을 이용하지 않음.
  • typeRoots 와 types 를 같이 사용하지 않음
profile
프론트엔드 개발자

0개의 댓글