问题
I've got an Outlook web add-in project based on the React and TypeScript scaffolding generated by the Yeoman Office Add-in Generator. However, the intellisense (I'm using Webstorm) appears to be missing almost all of the properties and methods for the Office.context.mailbox.item object. e.g. Only body and dateTimeCreated, not even subject and a bunch of others!
I'm not sure if this is an issue with the files generated by Yeoman, or something else (I'm very new to React). Below is a screenshot of the available props, and the index.tsx file that's generated; I'm trying to access a mail item's properties in the Office.initialize function.
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import { initializeIcons } from 'office-ui-fabric-react/lib/Icons';
import App from './components/App';
import './styles.less';
import 'office-ui-fabric-react/dist/css/fabric.min.css';
initializeIcons();
let isOfficeInitialized = false;
const title = 'My Outlook React Add-in';
const render = (Component) => {
ReactDOM.render(
<AppContainer>
<Component title={title} isOfficeInitialized={isOfficeInitialized} />
</AppContainer>,
document.getElementById('container')
);
};
/* Render application after Office initializes */
Office.initialize = () => {
isOfficeInitialized = true;
let item = Office.context.mailbox.item;
emailSubject = item.???
render(App);
};
/* Initial render showing a progress bar */
render(App);
if ((module as any).hot) {
(module as any).hot.accept('./components/App', () => {
const NextApp = require('./components/App').default;
render(NextApp);
});
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
回答1:
As it so happens, I was just discussing with a colleague yesterday, about how to make the d.ts file better for Outlook.
I just sent a pull request to DefinitelyTyped (which also produces the @types/office-js package): https://github.com/DefinitelyTyped/DefinitelyTyped/pull/26016. It should be merged soon.
If you want, in the meantime, you can just copy over the resulting d.ts file and use that. In fact, if your project has node_modules/@types/office-js
(I assume it does?), you can just temporarily update it manually on your local file system, with the copy from here (from the pull request): https://raw.githubusercontent.com/Zlatkovsky/DefinitelyTyped/235072eab26a40527778755dd477cce3bcc494ae/types/office-js/index.d.ts
来源:https://stackoverflow.com/questions/50518731/office-js-mail-object-properties-missing-in-typescript