One of the main challenges with creating modern JavaScript web applications is the relatively incomplete approach to ES modules. As an interim solution until all necessary use cases are solved, many developers create source code with ESM, and then transpile to either AMD, CJS, or UMD for easy usage within today’s browsers. As we work on creating Dojo 2 in a manner that is easy to use for both TypeScript and JavaScript users, one challenge we faced was how to support loader plugins and/or other dynamic module loading. AMD has long supported loader plugin syntax, and SystemJS supports loader plugins as well as System.import.

In our proposal on Better support for loader plugins in TypeScript, we came to the conclusion that adding true wildcard support would solve many of the challenges we faced. This extension makes it easy to implement features such as AMD loader plugins for text resources and other non-module code. After a healthy amount of discussion and thought, the TypeScript team agreed that adding support for shorthand ambient module declarations and wildcard chars in module names was a good idea.

This addition solves many challenges for developers working with TypeScript, and we’re very happy to see this feature land in TypeScript 2. It makes things like this possible:

declare module "json!*" {
    let json: any;
    export default json;
}

import d from "json!a/b/bar.json";
// lookup:
//    json!a/b/bar.json
//    json!*

This is yet another simple example of how great the open source community process can work to improve not only Dojo 2, but any project that leverages TypeScript!