Categories
TypeScript Answers

How to use namespaces with import in TypeScript?

Spread the love

Sometimes, we want to use namespaces with import in TypeScript.

In this article, we’ll look at how to use namespaces with import in TypeScript.

How to use namespaces with import in TypeScript?

To use namespaces with import in TypeScript, we can create ES6 modules and import them.

For instance, we write

UtilBase.ts

import * as path from "path";

export default class UtilBase {
  protected fixPath(value: string): string {
    return value.replace("/", path.sep);
  }
}

to export the UtilBase class as a default export.

Then we can import the module as a default import with

import UtilBase from "./UtilBase";
export default class UtilOne extends UtilBase {
  //...
}

Conclusion

To use namespaces with import in TypeScript, we can create ES6 modules and import them.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.