Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check attributes spelling when using multi level includes #1368

Open
frouo opened this issue May 24, 2021 · 1 comment
Open

Check attributes spelling when using multi level includes #1368

frouo opened this issue May 24, 2021 · 1 comment

Comments

@frouo
Copy link

frouo commented May 24, 2021

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

@stale
Copy link

stale bot commented Jul 21, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 21, 2021
@mtrezza mtrezza removed the stale label Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants