Search code examples
es6-promiseoffice-jsoffice-js-helpers

Cannot figure out how to use the OfficeExtension.Promise


Currently I am trying to use the OfficeExtension.Promise polyfill offered by Microsoft for developing Office Add-Ins. Unfortunately I am not able to get it to work thus far. From what I can tell these are only offered in the WordApi 1.2 and ExcelApi 1.2. Since I could not find separate node modules offering these api's I presume that these are included in the normal '@microsoft/office-js' node module. Additionally I have installed the office-js types as well.

Node modules

Node modules

Import statements

So far I have tried importing the 'OfficeExtension' class/namespace in the following ways.

import {OfficeExtension} from '@microsoft/office-js'
import {OfficeExtension} from 'office-js'
import {OfficeExtension} from '@types/office-js'

Error

All of these result in an intellisense error stating that the module cannot be found.

Error

Question

The concrete problem is that I do not know how to import the functionality in order to use the OfficeExtension.Promise polyfill. I could find no documentation that offers any help on this topic, so any advice or information would be greatly appreciated.


Solution

  • Unfortunately the error that is shown, actually states what is happening. 'office-js' does not export a module that can be used in a Typescript/React project. Office or OfficeExtension are global variables on the 'Window'. Therefore a /// tag or another script reference is needed, in order to import these variables.

    Link