Skip to content

Passing a model to a function and accessing static members #232

Closed
@mikew

Description

@mikew

I'm trying to write a function that takes a model class and calls .findAll({}), but TypeScript is giving me an error. This reproduces it:

async function createResource(model: typeof Model) {
  const results = await model.findAll({})
}

gives:

The 'this' context of type 'typeof Model' is not assignable to method's 'this' of type 'new () => Model<any>'.
  Cannot assign an abstract constructor type to a non-abstract constructor type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions