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

Commit 06750af

Browse files
author
Andy Hanson
committed
Document wildcard module declarations
1 parent 64c3564 commit 06750af

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pages/Module Resolution.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,33 @@ A non-relative import can be resolved relative to `baseUrl`, or through path map
4242
They can also resolve to [ambient module declarations](./Modules.md#ambient-modules).
4343
Use non-relative paths when importing any of your external dependnecies.
4444

45+
## Wildcard module declarations
46+
47+
Some module loaders such as [SystemJS](https://github.com/systemjs/systemjs/blob/master/docs/overview.md#plugin-syntax)
48+
and [AMD](https://github.com/amdjs/amdjs-api/blob/master/LoaderPlugins.md) allow non-JavaScript content to be imported.
49+
These typically use a prefix or suffix to indicate the special loading semantics.
50+
Wildcard module declarations can be used to cover these cases.
51+
52+
```ts
53+
declare module "*!text" {
54+
const content: string;
55+
export default content;
56+
}
57+
// Some do it the other way around.
58+
declare module "json!*" {
59+
const value: any;
60+
export default value;
61+
}
62+
```
63+
64+
Imports of the kind "*!text" and "json!*" can now be used.
65+
66+
```
67+
import fileContent from "./xyz.txt!text";
68+
import data from "json!http://example.com/data.json";
69+
console.log(data, fileContent);
70+
```
71+
4572
## Module Resolution Strategies
4673

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

0 commit comments

Comments
 (0)