This project is read-only.


reference a file and execute


It's possible to use the IO library and for example print to the console when executing a ts file:

declare var IO;
IO.print("hello world");

tsc -e somefile.ts

But it's for some reason not possible to reference an external definition file and do the same:

/// <reference path="io.d.ts"/>
IO.print("hello world");

I found a workaround:
Add also a reference to an empty ts file
/// <reference path="empty.ts"/>
/// <reference path="io.d.ts"/>
IO.print("hello world");

And compile it with the --out option

tsc -e somefile.ts --out somefile.js
Closed Apr 3, 2013 at 6:37 PM by billti
The IO module is not intended to be used by whatever code you are compiling & executing. Ideally, when your code executes, none of the objects the TypeScript compiler has setup would be available to you. This is only available as an artifact of the limitations of certain hosts in settings up a new context.

If you want to write to the console when you code executes after it is compiled, you should use the host methods of the native JavaScript environment (e.g. console.log), not the IO object the TypeScript compiler has left hanging around.