1

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.

Mavi Domates
  • 4,262
  • 2
  • 26
  • 45
  • Remove the `export {}` as it makes it *not* an ambient declaration file. – kelsny Oct 28 '22 at 18:22
  • If I remove that, I receive this: `Augmentations for the global scope can only be directly nested in external modules or ambient module declarations.ts(2669)` – Mavi Domates Oct 28 '22 at 19:58

0 Answers0