How to import two exported classes with the same name with TypeScript?

Sometimes, we want to import two exported classes with the same name with TypeScript.

In this article, we’ll look at how to import two exported classes with the same name with TypeScript.

How to import two exported classes with the same name with TypeScript?

To import two exported classes with the same name with TypeScript, we can use the as keyword to import a member with a different name.

For instance, we write

import { Class1 } from "../location1/class1";
import { Class1 as Alias } from "../location2/class1";

to Class1 from 2 different modules.

We import the 2nd Class1 as Alias so it won’t clash with the first one.

Then we use Alias to reference the 2nd Class1.

Conclusion

To import two exported classes with the same name with TypeScript, we can use the as keyword to import a member with a different name.