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

252
Vistas
How to use a .d.ts declaration file in a JS environment inside VSCode?

I have been working on a JavaScript library, and want to document it using TypeScript declaration files. Now the problem is that I couldn't understand how to work with the file as I am developing the library in Visual Studio Code.

So I have set up this simple example.

Here's my directory structure:

learning
|-- index.js
|-- greeting.js
|-- greeting.d.ts

Suppose I have the following greeting.d.ts file that documents the class Greeting:

// greeting.d.ts
export class Greeting {
    constructor(msg: string)
    greet(): void
}

And here's the greeting.js file that defines the logic of the class Greeting:

// greeting.js
class Greeting {
    constructor(msg) {
        this.msg = msg;
    }
    greet() {
        console.log(this.msg);
    }
}

module.exports = Greeting;

This file is imported by index.js whereby I do a simple greeting:

// index.js
var Greeting = require('./greet.js');

var g = new Greeting('Hello World!');
g.greet();

As is clear, I am currently using the CommonJS-style modules.

Now, while I am working in my JS files (note that I am not working in a TypeScript environment — I want to use TypeScript only for documentation purposes for now), such as index.js and greeting.js, I want to be able to get intellisense based on the greeting.d.ts file.

I have tried many options, such as setting the typeRoots options in the tsconfig.json file placed inside the directory learning, or modifying the include property in the same tsconfig.json file, but none seems to be a solution.

How to use a .d.ts declaration file in a JS environment inside VSCode?

about 4 years ago · Juan Pablo Isaza
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