---
title: "Use typed objects instead of loose arrays · Agent Wranglers"
url: https://agentwranglers.se/playbook/architecture/data-shapes/typed-data-objects
updated: 2026-10-20
licence: "All rights reserved"
---

# Use typed objects instead of loose arrays

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Data shapes](https://agentwranglers.se/playbook/architecture/data-shapes)
- Rule: Pass data between functions as a named type, such as a DTO or value object. Never use `object`, a plain dictionary or an untyped array that says nothing.
- How: Give each shape a class, record or type with named, typed fields. A reader and an agent can then see every field without running the code. Typos fail at build time, not in production. A map with typed keys and values, such as `Map<OrderId, Order>`, is a typed shape too.
- Check: The type checker rejects untyped shapes. Examples are PHPStan at level 6 or higher, which requires array value types, TypeScript with `strict`, or mypy with `--strict`.

Example:

```php
// Bad: what keys does this array have, and what types?
function createInvoice(array $data): array { /* ... */ }

// Good: the type says it
final readonly class InvoiceRequest {
    public function __construct(public CustomerId $customer, public Money $amount, public DateTimeImmutable $due) {}
}
function createInvoice(InvoiceRequest $request): Invoice { /* ... */ }
```

```ts
// Bad
function createInvoice(data: any) { /* ... */ }

// Good
type InvoiceRequest = { readonly customer: CustomerId; readonly amount: Money; readonly due: Date };
function createInvoice(request: InvoiceRequest): Invoice { /* ... */ }
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers architecture playbook: https://agentwranglers.se/playbook/architecture/data-shapes/typed-data-objects`.

- Next: [Wrap domain values in their own types](https://agentwranglers.se/playbook/architecture/data-shapes/value-objects)
- [Data shapes](https://agentwranglers.se/playbook/architecture/data-shapes)
