The reason why adding an import to your *.d.ts file suddenly broke the code that relied on it is because adding imports or exports to a *.d.ts (or really, any *.ts file) changes it from behaving like a script to acting like a module. This is important because scripts have global scope, whereas modules are locally scoped.
If you want to use imports while still having your declarations be "ambient", you just need to wrap them in a declare global {} block.
PS: I feel your frustration with the complexity of ambient declaration docs. I have a cheatsheet, which you might find helpful as it even covers the issue above.
The reason why adding an import to your
*.d.ts
file suddenly broke the code that relied on it is because adding imports or exports to a*.d.ts
(or really, any*.ts
file) changes it from behaving like a script to acting like a module. This is important because scripts have global scope, whereas modules are locally scoped.If you want to use imports while still having your declarations be "ambient", you just need to wrap them in a
declare global {}
block.PS: I feel your frustration with the complexity of ambient declaration docs. I have a cheatsheet, which you might find helpful as it even covers the issue above.
Cool, thanks for the input!