π νμ λͺ¨μμ§
- 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",
}; // β
- νκ°μ νλ‘νΌν°λ§ μ΅μ λλ‘ κ°μ Έμ€κΈ°
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,
}; // β
- μ«μ λ²μλ₯Ό μ§μ ν΄μ 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; // β