I think I know what you're trying to do — you want typescript to understand that the p
variable is set in the global scope without having to import { p } from ...
in every file.
If I'm not mistaken, what you need to do is make an ambient declaration:
declare const p: (message: string) => void // or whatever
This doesn't have to be declared in every file. Put it in a d.ts
file in a folder called typings/
and then include that file in your tsconfig:
"include": [
"typings/**/*",
...
],
Note: your d.ts file can't import any other modules. But it can use other ambient types that were declared in other d.ts files, without importing them. If you import something, then typescript will not treat your file as an ambient declaration and it won't work.