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

90
Vistas
Creating typescript interface from JSON object

Is there a way to import a JSON object into a Typescript program so that it is automatically strongly typed and constant?

So if I have this code in person.json:

{
  "name": "Steven",
  "eyeColor": "brown"
}

I want to be able to import it to a Typescript program as such:

// personTest.ts
const person = require('person.json');
console.log(person.name); // This should be fine
console.log(person.age);  // This should cause a compile-time error, because this property is not defined
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

add this on tsconfig.json

{

   ... //prev code

   "resolveJsonModule": true, 

}

then you can use ESM modules to import json file and it will be auto typed the object values

import person from './person.json' //be sure from the json path
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