1.

How to import a module in typescript?

Answer»

Modules can be imported using the import keyword. Here’s a detailed info into it:

IMPORTING individual exports from within a MODULE:

import { Employee } from "./Employee";
let empObj = new Employee("Best Interview Question", 1);
empObj.displayEmployee(); //OUTPUT: Employee Code: 1, Employee Name: Best Interview Question

Now, to import the exports within a module as a variable into ANOTHER module, USE this code:

import * as Emp from "./Employee"
console.log(Emp.age); // 10
let empObj = new Emp.Employee("Best Interview Question" , 2);
empObj.displayEmployee(); //Output: Employee Code: 2, Employee Name: Best Interview Question



Discussion

No Comment Found