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>
:
- TypeScript
- C++
- Swift
- Kotlin
interface Database extends HybridObject {
getAllUsers(): Record<string, number>
}
class HybridDatabase: public HybridDatabaseSpec {
std::unordered_map<std::string, double> getAllUsers();
}
class HybridDatabase: HybridDatabaseSpec {
func getAllUsers() -> Dictionary<String, Double>
}
class HybridDatabase: HybridDatabaseSpec() {
fun getAllUsers(): Map<String, Double>
}
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.