Matthew Ronemous

Require.js text! with Typescript

When loading HTML templates using Require.js/Text I discovered a pretty nifty trick with Typescript. Using the amd-dependency comment provides a cleaner syntax for including static javascript files.

Rather than doing this ugly approach.

declare module "text!post/list.html" { } 
import tpl = module("text!post/list.html");

You can do the same thing with a much cleaner syntax.

///<amd-dependency path="text!post/list.html"/>
...
var tpl = require('text!post/list.html');

The amd dependency comment can also be used to include static libraries as well.

TypeScript