type Entry = { id: string; title: string };
function parseEntry(value: unknown): Entry {
  if (typeof value !== 'object' || value === null ||
      !('id' in value) || typeof value.id !== 'string' ||
      !('title' in value) || typeof value.title !== 'string') {
    throw new Error('Invalid entry response');
  }
  return { id: value.id, title: value.title };
}
async function loadEntry(response: Response): Promise<Entry> {
  if (!response.ok) throw new Error(`HTTP ${response.status}`);
  return parseEntry(await response.json());
}
async function main() {
  console.log(await loadEntry(Response.json({ id: 'e1', title: 'Roof' })));
  try { await loadEntry(Response.json({ id: 'e1' })); }
  catch (error) { console.log(String(error)); }
}
void main();
