Po_tta_tt0
콩심콩 팥심팥 🌱
Po_tta_tt0
전체 방문자
오늘
어제
  • 분류 전체보기 (266)
    • 🐛 회고 (14)
    • 💭 생각 (2)
    • 🤸‍♀️ 내 프로젝트 (16)
      • FISH-NEWS (8)
      • MBTI 과몰입 테스트 (2)
      • twitter clonecoding with TS (4)
      • pilzagenda (2)
    • 👨‍👩‍👧‍👦 팀 프로젝트 (2)
      • 피우다 프로젝트 (0)
      • SEMO(세상의 모든 모임) (1)
      • 마음을 전하는 텃밭 (1)
      • Stackticon (0)
    • 👨‍💻 CS지식 (11)
    • ✍ 공부 (94)
      • JavaScript (21)
      • TypeScript (39)
      • Html (0)
      • CSS (2)
      • React (18)
      • NextJS (7)
      • Vue (1)
      • Python (1)
      • Django (0)
      • 개발환경 & 그 외 (2)
    • 🏄‍♀️ 코딩테스트 (99)
      • 🐍 Python (99)
    • 🐙 Git & GitHub (3)
    • 📑 오류기록 (8)
    • 📚 우리를 위한 기록 (9)
    • 수업 (3)
    • 강의 등 (2)
    • 👩‍🎓 SSAFY (0)
    • 👋 우테코 (0)

블로그 메뉴

  • 홈
  • 태그

공지사항

인기 글

태그

  • 시뮬레이션
  • 백준 숨바꼭질
  • BFS + DP
  • bfs
  • 플로이드 워셜
  • React
  • 자바스크립트
  • 이분탐색
  • 파이썬
  • dfs
  • react-router-dom
  • js
  • DP
  • 파이썬 다익스트라
  • 문자열
  • 구현
  • 백준
  • Next.js
  • 파이썬 감시 피하기
  • 백준 파이썬

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Po_tta_tt0

콩심콩 팥심팥 🌱

✍ 공부/TypeScript

[type-challenges] PickByType

2023. 7. 25. 20:19
반응형

문제

U에서 T 유형을 가진 속성들의 집합을 꺼냅니다

설명

/* _____________ Your Code Here _____________ */

type PickByType<T, U> = {[K in keyof T as T[K] extends U ? K: never]:T[K]}

type t = PickByType<Model, boolean>

/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'

interface Model {
  name: string
  count: number
  isReadonly: boolean
  isEnable: boolean
}

type cases = [
  Expect<Equal<PickByType<Model, boolean>, { isReadonly: boolean; isEnable: boolean }>>,
  Expect<Equal<PickByType<Model, string>, { name: string }>>,
  Expect<Equal<PickByType<Model, number>, { count: number }>>,
]

집중해야 할 점은 as다

  • K in keyof T T의 key를 K로 보고
  • as T[K] extends U 위의 value가 U를 extends하면?? K를 출력하고 아니면 never
  • 예전에 했던 것 같은데, 객체에서 key를 never로 두면 절대! 오면! 안돼!! 라는 표현이다
반응형
저작자표시 (새창열림)

'✍ 공부 > TypeScript' 카테고리의 다른 글

[type-challenges] EndsWith  (1) 2023.08.01
[type-challenges] StartsWith  (0) 2023.07.25
[type-challenges] Drop Char  (0) 2023.07.25
[type-challenges] IsNever  (0) 2023.07.04
[type-challenges] AnyOf< {[key:string]:never}와 {} type은 뭐가 다를까?>  (0) 2023.07.04
    '✍ 공부/TypeScript' 카테고리의 다른 글
    • [type-challenges] EndsWith
    • [type-challenges] StartsWith
    • [type-challenges] Drop Char
    • [type-challenges] IsNever
    Po_tta_tt0
    Po_tta_tt0
    감자의 코딩하는 블로그 콩심은데 콩나고 팥심은데 팥난다

    티스토리툴바