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

193
Vistas
module.export in typescript. import json list

It seems simple, this operates in javascript, but I'm a bit confused about typescript's closest equivalent. I'm trying to use module.exports in the way I know from javascript, passing data the json list data between 3 files.

in javascript the main file basically works as this: - main.js :

const { mainnet: addresses } = require("./addresses");

const token0 = addresses.tokens.busd;

so, main.ts would be? (i believe main issue is here):

import  { mainnet } from "./addresses/index";

token0 = mainnet.tokens.busd;

then typescript index.ts in ./address/index.ts (i believe this functions properly):

import  tokensMainnet  from './tokens-mainnet.json';

declare var module: any;
// "allowSyntheticDefaultImports" = true
module.exports = {
  mainnet: {
    tokens: tokensMainnet
  }
};

and tokensmainnet.json

{
  "busd": "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56",
  "wbnb": "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"
}

i can see from the metadata it's functioning:

enter image description here

so I believe the main problem with with importing this module in the main.ts

I've grazed over some sources such as with no luck https://www.typescriptlang.org/docs/handbook/modules.html

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

in typescript

add

"resolveJsonModule":true 

to package.json:

" Allows importing modules with a ‘.json’ extension, which is a common practice in node projects. This includes generating a type for the import based on the static JSON shape." -https://www.typescriptlang.org/tsconfig#resolveJsonModule

so add to main.ts:

import * as data from "./addresses/tokens-mainnet.json" 
    //...program code...
constructor(){
 let tokenAddress = data
    console.log(tokenAddress.busd)

}

:)

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