Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

253
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda