1

I have the following code:

console.log(fs.readdirSync(__dirname));

Which prints out the following:

[ 'index.js', 'objective.js', 'quest.js', 'user_objective.js' ]

However, my file directory setup is as follows:

enter image description here

Why would it think the .ts extension is .js?

tsconfig.json

{
  "compilerOptions": {
   
    "target": "es6",
  
    "module": "commonjs" /* Specify what module code is generated. */,
    "rootDir": "./src" /* Specify the root folder within your source files. */,
    "outDir": "./dist" /* Specify an output folder for all emitted files. */,
    "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
    // "preserveSymlinks": true,                         /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
    "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,

    /* Type Checking */
    "strict": true /* Enable all strict type-checking options. */,
   
    "skipLibCheck": true /* Skip type checking all .d.ts files. */
  },
  "exclude": ["node_modules"]
}

Snoopy
  • 1,257
  • 2
  • 19
  • 32

1 Answers1

0

Node.js doesn't support TypeScript.

Your TypeScript is compiled into JavaScript and stored in .js files ("outDir": "./dist" /* Specify an output folder for all emitted files. */,).

Node.js runs the resulting JavaScript.

The __dirname for the JS files contains JS files.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335