Let me start by saying I've read the workarounds that's described here: How do you explicitly set a new property on `window` in TypeScript?
I'm essentially trying to do the same thing, but the below configuration on a MacOS device, I'm getting compilation failures.
node -v ==> v.18.12.0
Dependencies from the package.json
file.
"dependencies": {
"@types/jest": "^29.2.0",
"jest": "^29.2.2",
"ts-jest": "^29.0.3",
"typescript": "^4.8.4"
}
tsconfig.json
file
{
"files": ["src/index.ts"],
"compilerOptions": {
"outDir": "./dist",
"target": "ES6",
"sourceMap": false,
"noImplicitAny": true,
"moduleResolution": "Node",
"typeRoots": ["./node_modules/@types", "src/types"]
}
}
What I have in the /src/types:
// index.d.ts
export {};
declare global {
interface Window {
Office: any;
}
}
And from the source files, I'm getting the error below:
Property
Office
does not exit on type 'Window & typeof globalThis'.
Weird thing is, Jest files are seeing the types, in fact I can run tests. It's only the actual source files which contain the logic that's failing to pick up the types.