Categories
TypeScript Answers

How to fix the ‘Error: *.default is not a constructor’ error with TypeScript?

Spread the love

Sometimes, we want to fix the ‘Error: *.default is not a constructor’ error with TypeScript.

In this article, we’ll look at how to fix the ‘Error: *.default is not a constructor’ error with TypeScript.

How to fix the ‘Error: *.default is not a constructor’ error with TypeScript?

To fix the ‘Error: *.default is not a constructor’ error with TypeScript, we should make sure the default export we’re importing is a class or constructor.

For instance, we write

export default class MapAction implements IMapAction {
  //...
}

to export the MapAction class as a default export with export default .

Then we can import the class in another module by writing

import MapAction from "./map-action";

Conclusion

To fix the ‘Error: *.default is not a constructor’ error with TypeScript, we should make sure the default export we’re importing is a class or constructor.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *