Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

197
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda