philli philli - 7 months ago 23
Javascript Question

TypeScript import export behaviour of modules

I'm currently bundling typings d.ts files with my modules, and I came across this weird behaviour:

import * as validator from "./ZipCodeValidator" // works
export * from "./ZipCodeValidator"; // works
export import validator = require("./ZipCodeValidator"); // works
export * as validator from "./ZipCodeValidator"; // does not work


Why does line 4 not show the same behaviour as line 3?

Answer

export * as validator from "./ZipCodeValidator"; // does not work

It does not work because it is not valid ES6 syntax. The import * / export * are valid es6 syntaxes. The closes you can get with ES6 style module is:

import * as _validator from "./ZipCodeValidator" // works  
export validator = _validator;
Comments