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

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Po_tta_tt0

콩심콩 팥심팥 🌱

✍ 공부/TypeScript

[type-challenges] Concat

2023. 5. 23. 21:07
반응형

 

 

 

0. 문제

Javascript의 Array.concat 함수를 타입 시스템에서 구현하세요.

 

 

 

1. 설명

/* _____________ Your Code Here _____________ */

type Concat<T extends readonly unknown[], U extends readonly unknown[]> =  [...T , ...U]

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

const tuple = [1] as const

type cases = [
  Expect<Equal<Concat<[], []>, []>>,
  Expect<Equal<Concat<[], [1]>, [1]>>,
  Expect<Equal<Concat<typeof tuple, typeof tuple>, [1, 1]>>,
  Expect<Equal<Concat<[1, 2], [3, 4]>, [1, 2, 3, 4]>>,
  Expect<Equal<Concat<['1', 2, '3'], [false, boolean, '4']>, ['1', 2, '3', false, boolean, '4']>>,
]

// @ts-expect-error
type error = Concat<null, undefined>

type Concat<T extends readonly unknown[], U extends readonly unknown[]> = [...T , ...U]
이와같이 T와 U Array<??>를 스프레드 연산으로 풀어주고,
T와 U는 readonly unknown[]을 extend해준다 : readonly가 들어가는 이유는 cases 3을 해결하기 위함

반응형
저작자표시

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

[type-challenges] Unshift  (0) 2023.05.23
[type-challenges] Push  (0) 2023.05.23
[type-challenges] If  (0) 2023.05.23
[type-challenges] Awaited  (0) 2023.05.23
[type-challenges] Exclude  (0) 2023.05.23
    '✍ 공부/TypeScript' 카테고리의 다른 글
    • [type-challenges] Unshift
    • [type-challenges] Push
    • [type-challenges] If
    • [type-challenges] Awaited
    Po_tta_tt0
    Po_tta_tt0
    감자의 코딩하는 블로그 콩심은데 콩나고 팥심은데 팥난다

    티스토리툴바