Closed
Description
Is your feature request related to a problem? Please describe
I use Typescript and I could not find a way to check object's attributes when using multi level includes.
One level include works very fine (as shown below), but what if we use multi level?
Describe the solution you'd like
Having a static pass-through function that returns the attribute:
attr<K extends Extract<keyof T, string>>(attr: K): K;
Usage could be like
.include(`${Comment.attr("post")}.${Post.attr("author")}`)
or
.include(`${Attributes<Comment>.get("post")}.${Attributes<Post>.get("author")}`)
Note: I don't pretend to be a Typescript expert so may consider the above suggestions as pseudo-code.
Additional context
export class Comment extends Parse.Object<{
post: Post;
text: string;
}> {
constructor(options?: any) {
super("Comment", options);
}
}
export class Post extends Parse.Object<{
author: Parse.User;
}> {
constructor(options?: any) {
super("Post", options);
}
}
export async function getComments() {
return await new Parse.Query(Comment)
.include("post") // here Typescript works very well, it checks for Comment's attributes: include(...key: ("post" | "text" | keyof Parse.BaseAttributes)[]): Parse.Query<Comment>
.include("post.author") // here Typescript underlines red
.find();
}
Screenshots
Thank you