[230625] Typescript 공식문서

1. Typescript Mapped Type 정독 및 정리 완료

  • 자세한건 노션 참고


  1. 객체 타입을 선언 할 때 key에다가 타입단언(as)를 하면 key에게만 적용된다.
  2. key선언할 때 대괄호[ ]와 in 을 써야만 key의 이름을 가지고 value에서 사용할 수 있다.
    • property : property (x)
    • [Property : string] : Property (x)
    • [Property in string] : Property (o)
type ExtractPII<Type> = {
  [Property in keyof Type]: Type[Property] extends { pii: true } ? true : false;
};
// P = 'name'
// Type = DBfields 제네릭으로 받을꺼
// keyof Type = 'id' | 'name'

// 2. Type['id'] 는 { format: "incrementing" } 이 될꺼임.
// 고로 extends { pii: true } 못함. -> ?왜못하지? -> 그냥 안들어있다 라고만 해석함...ㅠㅜ
// 3. false

type DBFields = {
  id: { format: "incrementing" };
  name: { type: string; pii: true };
};

type ObjectsNeedingGDPRDeletion = ExtractPII<DBFields>;

2. Typescript Template Literal Tyeps 정독 및 정리 완료

  • 자세한건 노션 참고
type EmailLocaleIDs = "welcome_email" | "email_heading";
type TL = `${EmailLocaleIDs}_TL`;
// "welcome_email_TL" | "email_heading_TL";

type FooterLocaleIDs = "footer_title" | "footer_sendoff";

type AllLocaleIDs = `${EmailLocaleIDs | FooterLocaleIDs}_id`;
// "welcome_email_id" | "email_heading_id" | "footer_title_id" | "footer_sendoff_id"

type Lang = "en" | "ja" | "pt";

type Month = 1 || 2|| 12

const DateText:`${number}${Month}월` = `${year}${month}월`

type LocaleMessageIDs = `${Lang}_${AllLocaleIDs}`;
// Lang이 3종류, AllLocaleIDs이 4종류 이므로 12가지가 나온다.
// "en_welcome_email_id" | "en_email_heading_id" | "en_footer_title_id" | "en_footer_sendoff_id" | "ja_welcome_email_id" | "ja_email_heading_id" | "ja_footer_title_id" | "ja_footer_sendoff_id" | "pt_welcome_email_id" | "pt_email_heading_id" | "pt_footer_title_id" | "pt_footer_sendoff_id"

3. typescript 오프라인 모임 및 발표

  • 오전 9~12시까지 발표 및 학습 진행
  • 핸드북 끝나고 다음주에는 레퍼런스 봄
  • 연습문제 3문제 풀어오기

Categories:

Updated:

Leave a comment