Skip to content

オブジェクトの変更

ts
// 顧客型
type Customer = {
  id: string
  name: string
  email: string
  archived: boolean
}

// 顧客をアーカイブ状態にする
export function archiveCustomer(customer: Customer): Customer {
  return {
    ...customer,
    archived: true,
  }
}

const activeCustomer: Customer = {
  id: '1',
  name: 'Alice',
  email: 'alice@example.com',
  archived: false,
}

const archivedCustomer = archiveCustomer(activeCustomer)

// { id: '1', name: 'Alice', email: 'alice@example.com', archived: true }
console.log(archivedCustomer)