official document about Typescript module을 읽을 때 약간 혼란 스럽습니다.Typescript에서 모듈을 가져 오는 올바른 방법은 무엇입니까?
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";
코드 라인이 상기 후 의해, ZipCodeValidator 이미로드되어, 현재 파일의 모듈로 제공 지퍼. 나중에 if 조건에서 다음 코드 줄에서 다시로드해야하는 이유는 무엇입니까?
let ZipCodeValidator: typeof Zip = require("./ZipCodeValidator");
주목 : 다른 모듈을 다른 방법으로로드합니다. 하나는 가져 오기이고 다른 하나는 필요합니다. 다른 방법을 사용하는 이유는 무엇입니까?
Question2 :
왜 함수 서명을 필요로 선언해야합니까? 선언은 무엇을합니까? 선언 된 경우 구현은 어디에 있습니까?