Categories
TypeScript Answers

How to use namespaces with import in TypeScript?

Spread the love

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 {
  //...
}

By John Au-Yeung

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

Leave a Reply

Your email address will not be published.