I've been researching how to properly declare globals in Typescript for my project. However, I'm having trouble finding the most updated solution.
Currently, I am working on getting my custom global declares set up with a d.ts
file. My Typescript project is built and bundled using webpack/ts-loader.
Here is a glimpse of my tsconfig.json file. Despite some guides suggesting that I don't need to set typeRoots
, I have tried it both with and without but encountered the same results.
{
"files": [
"app.ts",
],
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": false,
"target": "es5",
"declaration": false,
"sourceMap": true,
"skipLibCheck": true,
"lib": ["es6", "dom"],
"esModuleInterop": true,
"typeRoots": [
"./typings/",
"../../../../../node_modules/@types/"
]
}
}
My d.ts
file, named soho.d.ts
, includes the following declarations:
declare global {
namespace Soho {
}
interface Window {
Soho: Soho;
}
interface Soho {
Locale: any;
}
}
However, I am encountering this error in webpack:
TS2304: Cannot find name 'Soho'
When trying to use my global in the code like this:
Soho.Locale
Do you think there might be an issue with my tsconfig.json
or perhaps with my d.ts
file?