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

228
Visualizações
Use TypeScript declaration in corresponding JavaScript file

I've started learning typescript, but it's classic concept where both types and runtime code is inside one ts file doesn't seem particularly attractive to me. Instead I'd like to keep writing javascript as before but add to my modules d.ts files with typings for type checks, hints, etc..

So, as I see, when importing some js + d.ts couple into js file with enabled checkJs option typescript will check that file for correct type usage based on d.ts file. But what I also need is the same behavior for imported js module itself. I.e. make typescript know values of what types my js module is recieving, check correct usage of that types and check that module is implements declaration.

Sounds a bit confusing, I know, so let me describe with example:

// a.d.ts
export function a(val: string): string;
// a.js
// Correct module implementation
export function a(val) {
    return `Hello ${val}`;
}
// a.js
// There must be two errors:
// argument is a string that doesn't have a "toFixed" method,
// and function return type is not a string anyway
export function a(val) {
    return {val: val.toFixed()};
}

This is behavior that I would like to see, but not what actually happens. Because actually happens nothing; typescript doesn't use information from a.d.ts for a.js.

I've searched through https://www.typescriptlang.org/docs and doesn't seem to find anything helpful. Is it even possible? If it, how to achieve such behavior?

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