I am just studying about typescript and its module system.
Meanwhile, I found out Triple-Slash Deirectives.
I just thought it is alternative expression of import / export. but It don't work as a thought. In below codes, I want to use namespace Myconsole in test.ts files.
// Myconsole.ts
namespace MyConsole {
export function log(msg: string) {
console.log(msg);
}
}
// test.ts
/// <reference path="Myconsole.ts" />
MyConsole.log("log"); // ReferenceError occurs here. but no redline
namespace MyConsole2 {
export function foo(msg: string) {
console.log(msg);
}
}
MyConsole2.foo("ging"); // but this one works.
but when I ran ts-node test.ts
it spit out Reference Error: Myconsole is not defined
What makes me more confused is complie with tsc -d
command is working.
// test.js
/// <reference path="Myconsole.ts" /> // Do .ts file available in .js ...?
var MyConsole2;
(function (MyConsole2) {
function foo(msg) {
console.log(msg);
}
MyConsole2.foo = foo;
})(MyConsole2 || (MyConsole2 = {}));
MyConsole.log("log"); // ReferenceError occurs here. but no redline
MyConsole2.foo("ging");
I am so confused... How can I properly use Triple-Slash Directives?
Do I set additional config?? please give me an advise