[230608] TypeScript 공식문서 (Everyday types)

1. TypeScript Everyday types 정독 진행중

primitive type

  • 기본적인 데이터 타입 의미
  • string , number, boolean, null, undefined, symbol
  • 심볼은 레퍼런스 상세 챕터에서 살펴 볼 예정

arrays

  • 같은 타입 묶음

object type

  • 비원시 타입 (noe-primitive type)

Union

  • 여러 타입 중 하나 일 수 있는 값을 모델링
let id: number | string;

id = "1234"; // OK
id = 1234; // OK
id = true; // Error: Type 'boolean' is not assignable to type 'string | number'

type alias

  • 타입에 이름 붙이는 문법 (별칭)
type Point = {
  x: number;
  y: number;
};

//단순 별칭임을 주의해야함
type UserInputSanitizedString = string;

function sanitizeInput(str: string): UserInputSanitizedString {
  return sanitize(str);
}

let userInput = sanitizeInput(getInput());
userInput = "new input"; // NO ERROR

interface

interface Point {
  x: number;
  y: number;
}

//확장
interface Bear extends Animal {
  honey: boolean;
}

Categories:

Updated:

Leave a comment