There are two types: BaseType and BabyType.
export type BaseType = {
id: string
}
export type BabyType = BaseType & {
name: string
};
In a generic layer where <T extends BaseType>
is used, the item being dealt with is actually a 'BabyType' object.
updateItem(item: T): Promise<T> {
console.log(data) // {id: '6495f70a317b446b083f', name: 'Test'}
The goal in this layer is to dynamically remove the 'id' from the data while retaining all keys defined in BabyType.
The expected result should be:
console.log(data) // {name: 'Test'}
Attempts were made:
type OmitType = Omit<T, keyof BaseType>;
console.log(data as OmitType)
Unfortunately, the above approach did not work. The 'id' key still appeared in the console output.
Is there a solution to remove all key/value pairs that originate from BaseType?