When attempting to export a namespace from one .ts
file and import it into another .ts
file, I encountered an error:
NewMain.ts:2 Uncaught ReferenceError: require is not defined
. As someone new to TypeScript, I am still in the learning process. Below is a snippet from my tsconfig.json
file:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true
},
"files": [
"greeter.ts",
"Main.ts",
"RajIsh.ts",
"NewMain.ts"
],
"exclude": [
"node_modules"
]
}
In my NewMain.ts
file, I attempt to import a namespace:
import {DepartmentSection} from "./RajIsh"
class Employee{
name: string;
Display(username:string)
{
this.name=username;
console.log(this.name);
}
}
var person = new Employee();
var itCell= new DepartmentSection.ITCell("Information Technology Section");
console.log("Displaying from NewMain.ts by importing......");
console.log(person.Display("XYZ")+" belongs to "+ itCell.DisplaySectionName("Finance Revenue and Expenditure Section"));
console.log("Wooooooooo Hurrey!!!!!!!!!!!!!!!......");
The RajIsh.ts
file contains the namespace:
export namespace DepartmentSection {
export class Section {
name: string;
constructor(theName: string) {
this.name = theName;
}
Department(depatmentName: string = "") {
console.log(`${this.name} , ${depatmentName} !!`);
}
}
export class ITCell extends Section{
constructor(SectionName: string) {
super(SectionName);
}
DisplaySectionName(DepartmentName:string) {
console.log("Printing Section name...");
super.Department(DepartmentName);
}
}
export class LoanAndAccount extends Section {
constructor(SectionName: string) {
super(SectionName);
}
DisplaySectionName(DepartmentName:string) {
console.log("Printing another Section name...");
super.Department(DepartmentName);
}
}
}
I have tried using
import DepartmentSection = require('./RajIsh');
, but when trying to access the classes and functions, I receive the error Property 'ITCell' does not exist on type 'typeof' RajIsh
. What steps should I take next?