问题描述
我有一个基于Yeoman Office加载项生成器生成的React和TypeScript脚手架的Outlook Web加载项项目.但是,智能感知(我正在使用Webstorm)似乎缺少Office.context.mailbox.item对象的几乎所有属性和方法.例如只有body和dateTimeCreated创建,甚至没有主题和一堆其他东西!
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!
我不确定这是否是Yeoman生成的文件或其他问题(我对React很陌生).下面是可用道具的屏幕快照,以及生成的index.tsx文件;我正在尝试在Office.initialize函数中访问邮件项目的属性.
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>
推荐答案
碰巧的是,我昨天刚与一位同事讨论如何使d.ts文件更适合Outlook.
As it so happens, I was just discussing with a colleague yesterday, about how to make the d.ts file better for Outlook.
我刚刚向DefinitelyTyped发送了拉取请求(它也会生成@ types/office-js包): https://github.com/DefinitelyTyped/DefinitelyTyped/pull/26016 .应该尽快合并.
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.
同时,如果需要,您可以复制生成的d.ts文件并使用它.实际上,如果您的项目有node_modules/@types/office-js
(我想是吗?),则可以在本地文件系统上手动进行临时更新,并从此处进行复制(来自pull请求): https://raw.githubusercontent.com/Zlatkovsky/DefinitelyTyped/235072eab26a4053778 /office-js/index.d.ts
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
这篇关于TypeScript中缺少Office.js邮件对象属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!