type operation = 'create' | 'update' | 'delete';
type mutationKey = {
operation: operation;
id: K extends 'delete' | 'update' ? string : undefined; // want this field to be undefined if operation above is 'create'
}
// example 1
const ex1 = {
operation: "create"
}
// example 2
const ex2 = {
operation: "update",
id: "1"
}
当我有条件地在对象中添加operation: "create"
或任何其他操作时,有没有办法键入id
字段?