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:
- 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.
- 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.
- 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.
- 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.
- Make sure that the class you are trying to instantiate is not a namespace. Namespaces cannot be instantiated.
- 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.
- Make sure that you are using the correct syntax to instantiate the class. In TypeScript, classes must be instantiated with the
new
keyword. - Make sure that the class is being imported from the correct location.
- If you’re using a library like AJV, make sure that the class is being imported from the correct module.
- 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.