Darragh ORiordan

  • About
  • Articles
  • Projects
  • Hire

Stay up to date

Subscribe to the newsletter to stay up to date with articles, news and much more!

Read the Privacy Policy.

Socials & Contact

  • Follow on Twitter
  • Follow on GitHub
  • Follow on LinkedIn
  • mailto:darragh.oriordan(AT)gmail.com

Sitemap

AboutArticlesProjectsHire

© 2025 Darragh ORiordan. All rights reserved.

Typescript error "does not satisfy the constraint new" when using InstanceType in typegoose

  • #typescript
  • #mongodb
Photo by Lorenzo HerreraAugust 6, 2019

If you get an error when trying to use InstanceType from typegoose as a parameter to a method in typescript make sure you are importing it from typegoose explicitly.

There is a thing called InstanceType defined in JavaScript already. Typescript will use this by default and that's where the error is coming from.

// If you have a method like this and you're getting an error on InstanceType import the typegoose InstanceType explicitly...

import { InstanceType } from 'typegoose'

 private async updateInstance(
        foundInstance: InstanceType<EnvironmentInstance>,
        environmentInstanceStateQueryArgs: EnvironmentInstanceStateQueryArgs,
        userId: string
    ): Promise<EnvironmentInstance> {
        foundInstance.cloudEnvironmentState = await this.environmentInstanceService.getSingleEnvironmentInstance(
            environmentInstanceStateQueryArgs,
            userId
        )
        return foundInstance.save()
    }

Hey! Are you a developer?

🚀 Set Up Your Dev Environment in Minutes, Not Hours!

Tired of spending hours setting up a new development machine? I used to be, too—until I automated the entire process!

Now, I just run a single script, grab a coffee, and let my setup take care of itself.

Save 30+ hours configuring a new Mac or Windows (WSL) development environment.
Ensure consistency across all your machines.
Eliminate tedious setup and get coding faster!
Get Instant Access →