sequelize-typescript icon indicating copy to clipboard operation
sequelize-typescript copied to clipboard

Question: how to proper type the return type ?

Open Falci opened this issue 1 year ago • 2 comments

Question

Scenario: I have a custom query like this:

const results = await User.findAll({
  attributes: [
    "name",
    [cast(fn("COUNT", col("Posts.id")), "boolean"), "hasPosts"],
  ],
  include: {
    model: Post,
    attributes: [],
    required: false,
  },
  group: ["User.id", "Post.id"],
});

Can I (explicit or not) have result as:

interface ResultType {
  name: string;
  hasPosts: boolean;
}

Stretching a little bit: is there a way to make the result type to only have the properties included in the attributes?

Side question: could we have GitHub Discussions enable in this repo?

Falci avatar Apr 25 '23 10:04 Falci

@Falci One year later, did U find a way to have an explicit result type?

Jorgee97 avatar Apr 27 '24 22:04 Jorgee97

@Falci One year later, did U find a way to have an explicit result type?

No

Falci avatar Apr 28 '24 07:04 Falci