Error TS2351: This expression is not constructable. (AJV with TypeScript)

The “Error TS2351: This expression is not constructable” error in TypeScript is typically caused when you are trying to use a class that is not meant to be instantiated.

Here are a couple of things you can try to fix this error:

  1. Make sure that the class you are trying to instantiate is not abstract. Abstract classes cannot be instantiated and must be extended by a derived class.
  2. Make sure that the class you are trying to instantiate is not an interface. Interfaces cannot be instantiated and must be implemented by a class.
  3. Make sure that the class you are trying to instantiate is exported correctly. You should be able to import the class and then create an instance of it.
  4. Make sure that the class you are trying to instantiate is not a type alias. Type aliases cannot be instantiated and must be used as a type.
  5. Make sure that the class you are trying to instantiate is not a namespace. Namespaces cannot be instantiated.
  6. Make sure that the class you are trying to instantiate is in the correct scope, if the class is in a module, you may need to import it.
  7. Make sure that you are using the correct syntax to instantiate the class. In TypeScript, classes must be instantiated with the new keyword.
  8. Make sure that the class is being imported from the correct location.
  9. If you’re using a library like AJV, make sure that the class is being imported from the correct module.
  10. Check if there’s any other error in the file or in the project that is blocking the instantiation of the class.

These are some general suggestions, the actual cause of the error may vary depending on the specific circumstances. It would be helpful to check the code around the line where the error is thrown, this will give more information about the problem.

Leave a Reply