Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Document wildcard module declarations #318

Merged
2 commits merged into from
Jun 24, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions pages/Module Resolution.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,33 @@ A non-relative import can be resolved relative to `baseUrl`, or through path map
They can also resolve to [ambient module declarations](./Modules.md#ambient-modules).
Use non-relative paths when importing any of your external dependnecies.

## Wildcard module declarations

Some module loaders such as [SystemJS](https://github.com/systemjs/systemjs/blob/master/docs/overview.md#plugin-syntax)
and [AMD](https://github.com/amdjs/amdjs-api/blob/master/LoaderPlugins.md) allow non-JavaScript content to be imported.
These typically use a prefix or suffix to indicate the special loading semantics.
Wildcard module declarations can be used to cover these cases.

```ts
declare module "*!text" {
const content: string;
export default content;
}
// Some do it the other way around.
declare module "json!*" {
const value: any;
export default value;
}
```

Imports of the kind "*!text" and "json!*" can now be used.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would (1) change to active voice (2) be more explicit about the type of "*!text"/"json!*" ('imports of the kind' sounds vague to me). Something like:

Now you can import things that match "*!text" and "json!*".

Also you should backtick-quote "*!text" and "json!*" because the stars seem to be parsed as italic right now.


```ts
import fileContent from "./xyz.txt!text";
import data from "json!http://example.com/data.json";
console.log(data, fileContent);
```

## Module Resolution Strategies

There are two possible module resolution strategies: [Node](#node) and [Classic](#classic).
Expand Down