-
Notifications
You must be signed in to change notification settings - Fork 0
Pre Processing Macros
There are a few different preprocessing macros (Statements that are executed before the actual compilation.) that significantly speed up the TypeScript programming process and ease of use if used properly.
The @include file
macro allows very easy reference of a file and will include the script at the same time. You can also give a name to the file so that you can access it, @include "file":FriendlyName
, allows you to afterwards use FriendlyName.method();
If you're including a file from the currently directory with the name "Helper.ts" you may simply use:
@include Helper
Would reference the file "Helper.ts" and additionally include it at runtime. The output of the example file when pre-processed would look similar to:
/// <reference path="/path/to/helper/Helper.ts" />
var Helper = _typeinclude("/path/to/helper/Helper.ts");
Which would allow you to now access anything in Helper by simply calling Helper.method();
If you need to include a file from a different directory or assign the file another classname you may use this method:
@include "./path/Helper.ts":Helper
Would reference the file "Helper.ts" from the path "path" and additionally include it at runtime with the name "Helper". The output of the example file when pre-processed would look similar to:
/// <reference path="./path/Helper.ts" />
var Helper = _typeinclude("./path/Helper.ts");
If you changed the ":Helper" at the end of the inclusion it would change the variable definition name "Helper" to whatever you desire.
To simply reference a file in your script you can use the macro @reference <file>
.
@reference "./path/File.ts"
Would reference the file "File.ts" in the "path" folder. The output of the example file when pre-processed would look like:
/// <reference path="./path/File.ts" />