Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
How to include functions in namespace when don't have module?

How to include functions in namespace / module when don't have module?

example: I have a namespace:

namespace Java {}

in typescript, usually when we need a function in namespace or module, we add 'export':

namespace Java {
    export function version() {
        return "java8";
    }
}
namespace JavaScript {
    function JavaVer() {
        return Java.version();
    }
}

But if I set module to none:

// tsconfig
"module": "none",

If module is none, I cannot use import / export:

website/sourcecode/main.ts:17:21 - error TS1148: Cannot use imports, exports, or module augmentations when '--module' is 'none'.

17 export function version() {}

so what can I do?

image: enter image description here

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use a plain object:

TS Playground

const Java = {
  version () {
    return "java8";
  },
};

const JavaScript = {
  JavaVer () {
    return Java.version();
  },
};

const vJ = Java.version(); // string
const vJS = JavaScript.JavaVer(); // string
console.log(vJ === vJS); // true

about 4 years ago · Juan Pablo Isaza Report

0

It was answered in here: It's actually "can't have any imports or exports at the top level". Imports and exports inside namespaces are fine because they don't export anything from .ts file at runtime, and as long as file remains 'not a module' module=None works fine. Long explanation here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!