sequelize / sequelize-typescript

Decorators and some other features for sequelize

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: how to proper type the return type ?

Falci opened this issue · 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 One year later, did U find a way to have an explicit result type?

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

No