Skip to main content

Typed maps (Record<string, T>)

A typed map is an object where each value is of the given type T.

For example, if your API returns a map of users with their ages, you could use a Record<string, number>:

interface Database extends HybridObject {
getAllUsers(): Record<string, number>
}
tip

While typed maps are very efficient, Nitro cannot sufficiently optimize the object as keys are not known in advance. If possible, avoid typed maps and use arrays for unknown number of items, or strongly typed objects for known number of items instead.