I recently created two files:
main.ts:
///<reference path="./external.ts"/>
welcome();
external.ts
var welcome = function() {
console.log("hi there");
}
After compiling both files to JavaScript and running them using the command: $ node main.js
I was surprised when the 'welcome' function didn't execute as expected. Instead, I encountered an error:
ReferenceError: welcome is not defined
Upon researching about triple-slash directive (https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html), it was mentioned that:
The compiler does a preprocessing pass on input files to resolve all triple-slash reference directives. This process includes adding additional files to compilation.
Despite this explanation, I still struggle to comprehend why the function from external.ts file couldn't be accessed.