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

242
Visualizações
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 à 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