I am a bit confused when reading official document about Typescript module.
declare function require(moduleName: string): any;
// why declare require?
import { ZipCodeValidator as Zip } from "./ZipCodeValidator";
// Zip is being imported here, right?
if (needZipValidation) {
let ZipCodeValidator: typeof Zip = require("./ZipCodeValidator");
// Zip is already imported before if statement, why import again?
let validator = new ZipCodeValidator();
if (validator.isAcceptable("...")) { /* ... */ }
}
Question1:
import { ZipCodeValidator as Zip } from "./ZipCodeValidator";
After this above line of code, ZipCodeValidator is already loaded, and available as Zip in the module of current file. Why later in the if condition load it again at the following line of code?
let ZipCodeValidator: typeof Zip = require("./ZipCodeValidator");
Noted: They load the same module using different method, one is import, the other is require. Why using different way?
Question2:
Why do you need to declare require function signature? What does declare do? If declared, where is the implementation?