I have a package which is shared among other packages in my project:
export class User {
constructor(
public id: string;
public email: string;
public name: string;
){}
}
in my other package where I use this I’ve added an augmentation:
// src/mapper.ts
declare module "@shared/types" {
namespace User {
let test: () => User;
}
}
and an implementation too:
// src/mapper.ts
User.test= (...) =>
new User({
id: "test",
email: "[email protected]",
name: "test"
});
My problem is that if I use this elsewhere in my app:
// src/elsewhere.ts
console.log(`User.test is: ${User.test}`);
this will print undefined
. The project builds properly and I can’t see errors in VS Code either. What am I doing wrong? How can I make sure that these augmentations are properly loaded and I get a compiler error if not?