function total(text: string): number { const invoice = JSON.parse(text); return invoice.itmes?.length ?? 0; } console.log(total('{"items":[1,2]}'));