🏁Utility

Utility 폴더의 기능과 역할을 소개합니다.

utility 폴더는 주로 프로젝트에서 여러 부분에서 공통적으로 사용되는 유틸리티(utility) 타입들을 모아놓은 폴더입니다. 코드의 가독성과 재사용성을 높이기 위해 유용한 타입들을 한 곳에 모아 정리하는 데 목적이 있습니다.

아래는 type > utility 폴더에 있는 유틸리티 타입들과 해당 타입들의 역할을 표로 정리한 것입니다:

타입 (Type)
역할 (Role)
예시 (Example)

AsyncFnReturn<T>

주어진 비동기 함수 T의 반환 타입을 추출

type Example = AsyncFnReturn<() => Promise<number>>; Example = number

DeepMutable<T>

주어진 객체 T의 모든 속성을 mutable로 변환

type Example = DeepMutable<{ readonly a: number; readonly b: { readonly c: number; readonly d: string }; }>; Example = { a: number; b?: { c? : number; d? : string }; }

DeepNullAble<T>

주어진 객체 T의 모든 속성에 null 또는 해당 속성의 타입을 유지

type Example = DeepNullAble<{ a: number; b: { c : number; d : string }; }>; Example = { a: number | null; b?: { c? : number | null; d? : string | null } | null };

DeepOmitReadOnly<T>

주어진 객체 T의 모든 속성에서 readonly를 제거

type Example = DeepOmitReadOnly<{ readonly a: number; readonly b: string; c: { readonly d : number; e : string }; }>; Example = { c : { e: string }; }

DeepPartial<T>

주어진 객체 T의 모든 속성을 optional로 변환

type Example = DeepPartial<{ a: number; b: { c : number; d : string }; }>; Example = { a?: number; b?: { c? : number; d? : string }; }

IfEquals<X, Y, A, B>

주어진 두 개의 타입 XY가 동일한지 비교하여 A 또는 B를 반환

type Example1 = IfEquals<number, string, true, false>; type Example2 = IfEquals<number, number, true, false>; Example1 = true Example2 = false

ItemOf<T>

주어진 배열 T의 모든 아이템을 합친 유니온 타입을 생성

type Example = ItemOf<['a', 'b', 'c']>; Example = "a" | "b" | "c"

MockedFn<T>

주어진 함수 타입 T를 목(mock) 함수 타입으로 변환

export type MockedFn<T extends (...params: any) => any> = jest.Mock & ((...args: Parameters<T>) => ReturnType<T>);

Mutable<T>

주어진 객체 T의 모든 속성을 mutable로 변환

type Example = Mutable<{ readonly a: 1; b: 1 }>; Example = { a: 1; b: 1; }

NullAble<T>

주어진 객체 T의 모든 속성을 nullable로 변환

type Example = NullAble<{ a: 1; b: 1 }>; Example = { a: 1 | null; b: 1 | null }

OmitReadOnly<T>

주어진 객체 T의 모든 속성 중 readonly 속성을 제거하는 유틸리티 타입입니다.

type Example = OmitReadOnly<{ readonly a: number; b: string; readonly c: string; }>; Example = { b : string; }

Paginated<T>

주어진 타입 T의 결과와 페이징을 나타내는 객체를 결합

export type Paginated<T> = { next: string | null; results: T; };

Parameter<T>

주어진 함수 타입 T의 매개변수 타입을 추출

type Example = Parameter<(value: number) => void> Example = number

ReadonlyKeysOf<T>

주어진 객체 Treadonly 속성의 키를 추출

type Example = ReadonlyKeysOf<{ readonly a: number; b: string; readonly c: string; }>; Example = "a" | "c"

ValueOf<T>

주어진 객체 T의 모든 속성의 값으로 이루어진 유니온 타입을 생성

`type Example = ValueOf<{ a: number;

Last updated