전체 글
[type-challenges] IsNever
문제 input type으로 T를 받는 IsNever type을 구현하십시오. 만약 T의 유형이 never으로 확인되면 true를 반환하고 아니면 false를 반환합니다 설명 /* _____________ Your Code Here _____________ */ type IsNever = [T] extends [never] ? true : false /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect, Expect, Expect, Expect, Expect, Expect, Expect, ] 왜 [T]와 [never]일까? type ..
[type-challenges] AnyOf< {[key:string]:never}와 {} type은 뭐가 다를까?>
문제 Python의 any function을 타입 시스템으로 구현하세요 배열을 사용하고 배열의 요소가 참이면 true를 반환합니다. 배열이 비어 있으면 false를 반환합니다 설명 /* _____________ Your Code Here _____________ */ type False = 0 | '' | false | [] |undefined | null | {[key:string]:never} type AnyOf = T[number] extends False ? false: true type t = AnyOf type tt = AnyOf type temp = 0 extends null ? 'f' : 't' /* _____________ Test Cases _____________ */ import t..
[type-challenges] Diff
문제 0과 01에서 차이가 있는 개체를 가져옵니다 설명 /* _____________ Your Code Here _____________ */ type Diff = Omit /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type Foo = { name: string age: string } type Bar = { name: string age: string gender: number } type Coo = { name: string gender: number } type cases = [ Expect, Expect, Expect, Expect, ] Omit을 이용합..
[type-challenges] KebabCase
문제 camelCase나 PascalCase를 kebab-case로 바꿔주세요 FooBarBaz -> foo-bar-baz 설명 /* _____________ Your Code Here _____________ */ type KebabCase = S extends `${infer A}${infer B}` ? B extends Uncapitalize ? `${Uncapitalize}${KebabCase}` : `${Uncapitalize}-${KebabCase}` : S /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect, Expec..
A = [{ a:string, b:string}]와 type B = { a:string, b:string}[]의 차이가 뭘까요?
하루가 질문했던 내용에 당일 해답을 주지 못해서 다음날 고민해보다가 해결한 기록입니다 글도 남길 겸, 타입스크립트 스터디와 재이에게 정보도 줄 겸! 이렇게 블로그를 작성했습니다 😉👍 멋진 팀원이죠? 얼른 본론으로 들어갈게요 문제가 뭐였나요? 하루가 질문한 내용은, 상위 컴포넌트에서 type A = [{ a:string, b:string }] type B = { a:string, b:string }[] A 타입으로 작성된 props를 받을 때, type을 B로 명시하면 발생하는 에러에 관한 것이었습니다. 배열의 크기는 항상 1로 일정하고, 똑같이 배열 안에 a, b string이 들어있는 객체를 보내는 것은 똑같은데, 이 타입이 무슨 차이가 있어서 달라질까요? 하는 내용이었습니다. 그래서 무슨 차이가 있나..
[type-challenges] Merge
문제 두개의 타입을 새로운 타입으로 병합하세요. 두번째 타입이 첫번째 타입을 덮어씁니다. 설명 /* _____________ Your Code Here _____________ */ type Merge = {[P in keyof F | keyof S]: P extends keyof S ? S[P] :P extends keyof F ? F[P]:never} /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type Foo = { a: number b: string } type Bar = { b: number c: boolean } type cases = [ Expect,..
[type-challenges] String to Union
문제 String을 Union type으로 변환하시오. output은 input으로 받은 string letters의 유니온 타입이어야 합니다 설명 /* _____________ Your Code Here _____________ */ type StringToUnion = T extends `${infer A}${infer B}` ? StringToUnion :P[number] /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type t = StringToUnion type cases = [ Expect, Expect, Expect, Expect, ] 우와~~ 제가 ..
[type-challenges] Absolute
문제 number, string 혹은 bigint를 받는 Absolute 타입을 만드시오 output은 양의 정수 string입니다 설명 /* _____________ Your Code Here _____________ */ type Absolute = `${T}` extends `${'-'}${infer P}`? P :`${T}` /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type t = Absolute type cases = [ Expect, Expect, Expect, Expect, Expect, Expect, Expect, Expect, Expect, E..
[type-challenges] Append to object
문제 주어진 인터페이스에 새로운 필드를 추가한 object 타입을 구현하세요. 이 타입은 세 개의 인자를 받습니다. 설명 /* _____________ Your Code Here _____________ */ type AppendToObject = {[P in keyof T | U]:P extends keyof T ? T[P] : V} /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type test1 = { key: 'cat' value: 'green' } type testExpect1 = { key: 'cat' value: 'green' home: boolean ..
[type-challenges] Flatten
문제 주어진 배열을 플랫한 배열 타입으로 바꾸는 Flatten 타입을 구현하세요. 설명 /* _____________ Your Code Here _____________ */ type Flatten = T extends [any:infer K, ...a: infer P] ? K extends any[] ? Flatten : Flatten :S /* _____________ Test Cases _____________ */ import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect, Expect, Expect, Expect, Expect, ] // @ts-expect-error type error = Flatten 바로..