Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

TypeScript Error: Argument of type 'Model<T, {}, {}, {}>' is not assignable to parameter of type 'Collection<T>'. #88

Open
Labels
bugSomething isn't working help wantedExtra attention is needed
@sojharo

Description

I am getting this weird typescript error when I put Mongoose Model in constructor.

const ListingsDataSource = new Listings(ListingModel)

My Listing Model is defined like this:

export default class Listings extends MongoDataSource<Listing> {
 getListing(_id: string) {
 return this.findOneById(_id, { ttl: MINUTE });
 }
}

My Mongoose Model is defined like this:

const listingSchema = new Schema<Listing>({
 name: { type: String, required: true },
 description: { type: [String], required: true }
});
const ListingModel = model<Listing>("Listing", listingSchema);
export default ListingModel;

My Listing Interfact is defined like this:

export interface Listing {
 _id: ObjectId;
 name: string;
 description: string[];
}

But when I pass my Mongoose Model to DataSource based class. I get following TypScript error:

TypeScript Error: Argument of type 'Model<Listing, {}, {}, {}>' is not assignable to parameter of type 'Collection<Listing>'.

I have tried many ways but this is not getting solved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /