How to import a module in typescript?
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
BY Best Interview Question ON 12 May 2020