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?