Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Definindo o Tipo de Evento

Antes de buscar dados, vamos definir o tipo TypeScript que representa um evento. Crie o arquivo src/types.ts:

Arquivo: web/src/types.ts
export interface Event {
  id: number;
  title: string;
  description: string;
  location: string;
  date: string;
  capacity: number;
  created_at: string;
  organizer_name: string;
}

Código 7-3: Tipo que espelha o JSON retornado por GET /api/events.

Esse tipo espelha exatamente os campos que o backend retorna. Se o backend mudar a forma da resposta, o TypeScript avisa nos lugares que usam esse tipo — antes de a página quebrar.