[TYPECRIPT] Omit type when extending an interface Cách loại trừ các thuộc tính khỏi giao diện (ok)

https://stackoverflow.com/questions/51063976/how-to-exclude-properties-from-interface-while-inheriting

Typescript >3.5

type Person = {
    name: string;
    age: number;
    location: string;
};

type QuantumPerson = Omit<Person, "location">;

// equivalent to
type QuantumPerson = {
    name: string;
    age: number;
};

Hoặc

type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>

Last updated

Navigation

Lionel

@Copyright 2023