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

196
Views
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 answers
Answer question

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 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!