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

227
Vistas
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 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