Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!