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.