Pogreška prilikom pokušaja pokretanja transpajlanog TypeScript koda koristeći namespaceove


Pokušavam iskoristiti "namespace" u TypeScriptu.

Evo moje tsconfig.json datoteke:

{
  "compilerOptions": {
    "target": "ES2017",                                /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
    "module": "amd",                           /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
    "outFile": "dist/bundle.js",
    "outDir": "./dist",                        /* Redirect output structure to the directory. */
    "rootDir": "./src",                       /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
    "strict": true,                                 /* Enable all strict type-checking options. */
    "alwaysStrict": true,                        /* Parse in strict mode and emit "use strict" for each source file. */
    "typeRoots": ["./node_modules/@types"],                             /* List of folders to include type definitions from. */
    "esModuleInterop": true,                        /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
    "skipLibCheck": true,                           /* Skip type checking of declaration files. */
    "forceConsistentCasingInFileNames": true,        /* Disallow inconsistently-cased references to the same file. */
    "lib": [
      "es2021",
    ]
  },

}

Imam sljedeći kod: src/code/code.darwin.ts:

namespace Test {
    export const terminator = () => console.log('DARWIN');
}

src/code/code.ts:

namespace Test {
    export class ATest {
        public terminate() {
            terminator();
        }
    }
}

src/outer.ts:

/// <reference path="./code/code.ts" />

Test.terminator();

Kad to kompajliram - sve je u redu, ali kad pokušam pokrenuti:

/Users/talrofe/Desktop/test/dist/bundle.js:12
Test.terminator();
     ^

TypeError: Test.terminator is not a function
    at Object.<anonymous> (/Users/talrofe/Desktop/test/dist/bundle.js:12:6)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
    at internal/main/run_main_module.js:17:47
talrofe@moranamar-g3 test %