Skip to content

Check attributes spelling when using multi level includes #1368

Closed
@frouo

Description

@frouo

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

Capture d’écran 2021-05-24 à 13 25 44

Capture d’écran 2021-05-24 à 13 24 44

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions