nodejs-datastore
nodejs-datastore copied to clipboard
Add support for generic types
Is your feature request related to a problem? Please describe.
While the interfaces are well typed, we have to resort to casting results when generics could provide an elegant solution.
Describe the solution you'd like
type User = {
name: string;
};
// get
const user = await datastore.get<User>(key);
user.hello; // Property 'hello' does not exist on type 'User'
// get with multiple keys of the same type
const users = await datastore.get<User[]>(keys);
// get with multiple keys of various types
const [user, dog, cat] = await datastore.get<[User, Dog, Cat]>(keys);
// runQuery
const [users] = datastore.runQuery<User>(query);
users.forEach((user) => {
user.hello; // Property 'hello' does not exist on type 'User'
});
// save
await datastore.save<User>({
key,
data: {
hello: "world" // Object literal may only specify known properties, and 'hello' does not exist in type 'User'
}
});
Describe alternatives you've considered
Not any that I'm aware of!
Additional context
Not much to add!