I'm trying to do something but unsure how. To summarise I am wanting to override the types of everything exported from a "module" using a separate "module".
I am wanting three modules, one for the runtime, two for overriding the types of the first (for uses in different environments, the runtime module will handle the environment itself).
Can I do something like this?
// method.ts
export function method(value: unknown) {
if (typeof value === 'string') return 'string';
else if (typeof value === 'number') return 'number';
else return 'unknown';
}
// number.d.ts
declare module './method' {
declare function method(value: number): string;
}
// string.d.ts
declare module './method' {
declare function method(value: string): string;
}
// index.ts
import { method } from './method';
import './number';
method('42'); // <- i want this to error
// ^? method(value: unknown): ...
// im wanting its signature to be method(value: number): ...