Skip to content

yanggwangseong/TypeCollection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

TypeCollection

πŸ“• νƒ€μž… λͺ¨μŒμ§‘

PartialProps

  • Partial νƒ€μž…μ€ λͺ¨λ“  ν”„λ‘œνΌν‹°λ₯Ό μ˜΅μ…”λ„λ‘œ κ°€μ Έμ˜¬λ•Œ μ‚¬μš©ν•˜λŠ”λ°
  • λͺ¨λ“  ν”„λ‘œνΌν‹°λ₯Ό κ°€μ Έμ˜€λŠ”λ° νŠΉμ • ν”„λ‘œνΌν‹°λŠ” μ˜΅μ…”λ„λ‘œ κ°€μ Έμ˜€κ³  μ‹Άμ„λ•Œ μ‚¬μš©
export interface Member {
  memberId: string;
  groupId: string;
  invitationAccepted: boolean;
  role: "user" | "admin";
}

/**
 * {
 *  memberId: string;
 *  groupId: string;
 *  invitationAccepted: boolean;
 *  role?: "user" | "admin";
 * }
 */
type CreateMember = PartialProps<Member, "role">;

const createMember: CreateMember = {
  memberId: "123",
  groupId: "123",
  invitationAccepted: true,
}; // βœ…

const createMember2: CreateMember = {
  memberId: "123",
  groupId: "123",
  invitationAccepted: true,
  role: "user",
}; // βœ…

const createMember3: CreateMember = {
  memberId: "123",
  groupId: "123",
}; // ❌

const createMember4: CreateMember = {
  memberId: "123",
  groupId: "123",
  role: "user",
}; // ❌

PartialSelect

  • ν•œκ°œμ˜ ν”„λ‘œνΌν‹°λ§Œ μ˜΅μ…”λ„λ‘œ κ°€μ Έμ˜€κΈ°
export interface Member {
  memberId: string;
  groupId: string;
  invitationAccepted: boolean;
  role: "user" | "admin";
}

/**
 * {
 *  groupId?: string | undefined;
 *  role?: "user" | "admin" | undefined;
 * }
 */
type CreateMember = PartialSelect<Member, "role" | "groupId">;

const createMember: CreateMember = {}; // βœ…
const createMember2: CreateMember = {
  role: "user",
}; // βœ…
const createMember3: CreateMember = {
  role: "user",
  groupId: "123",
}; // βœ…
const createMember4: CreateMember = {
  role: "user",
  groupId: "123",
  invitationAccepted: true,
}; // ❌

NumberRange

  • 숫자 λ²”μœ„λ₯Ό μ§€μ •ν•΄μ„œ number νƒ€μž…λ³΄λ‹€ 더 쒁은 νƒ€μž…μ„ 톡해 νƒ€μž… μ•ˆμ •μ„±μ„ 높일 수 μžˆμŠ΅λ‹ˆλ‹€.
type NumberRange<
  L extends number,
  H extends number,
  LAcc extends any[] = [],
  HAcc extends any[] = [],
  Acc extends number[] = []
> = L extends LAcc["length"]
  ? H extends HAcc["length"]
    ? Acc[number] | HAcc["length"]
    : NumberRange<L, H, LAcc, [...HAcc, L], [...Acc, HAcc["length"]]>
  : NumberRange<L, H, [...LAcc, L], [...LAcc, L], Acc>;

/*
 * 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
 */
export type FeedPaginateLimit = NumberRange<1, 10>;
const limit1: FeedPaginateLimit = 10; // βœ…
const limit2: FeedPaginateLimit = 1; // βœ…
const limit3: FeedPaginateLimit = 3; // βœ…
const limit4: FeedPaginateLimit = 11; // ❌
const limit5: FeedPaginateLimit = 100; // ❌

About

πŸ“• νƒ€μž… λͺ¨μŒμ§‘

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published