【问题标题】:Office.SeriesTime TypeScript definition is missing the Properties only has MethodsOffice.SeriesTime TypeScript 定义缺少属性只有方法
【发布时间】:2021-10-29 13:42:48
【问题描述】:

Office.context.mailbox.item.recurrence.getAsync() 返回一个对象,但我无法将其部分转换为其他变量。 例如接口 Office.SeriesTime 只定义了 GetXXX() 方法

/**
 * Gets the duration in minutes of a usual instance in a recurring appointment series.
 * 
 * [Api set: Mailbox 1.7]
 *
 * @remarks
 * 
 * **{@link https://docs.microsoft.com/office/dev/add-ins/outlook/understanding-outlook-add-in-permissions | Minimum permission level}**: `ReadItem`
 * 
 * **{@link https://docs.microsoft.com/office/dev/add-ins/outlook/outlook-add-ins-overview#extension-points | Applicable Outlook mode}**: Compose or Read
 */
getDuration(): number;

例如这不会编译,因为接口 Office.SeriesTime 没有定义属性。

    const fixedRecurrence: Office.SeriesTime = recurrence.seriesTime;
    if (fixedRecurrence.endYear === 0) {
      fixedRecurrence.endYear = fixedEndDate.getFullYear();
      fixedRecurrence.endMonth = fixedEndDate.getMonth() + 1;
      fixedRecurrence.endDay = fixedEndDate.getDate();
    }

【问题讨论】:

    标签: outlook office-js outlook-addin outlook-web-addins


    【解决方案1】:

    查看Office.SeriesTime interface 成员。看来您需要改用getEndDate() 方法,它允许以以下ISO 8601 日期格式获取重复模式的结束日期:"YYYY-MM-DD"

    // This example gets the end date of a recurring appointment series.
    Office.context.mailbox.item.recurrence.getAsync(callback);
    
    function callback(asyncResult) {
        var context = asyncResult.context;
        var recurrence = asyncResult.value;
        var endDate = recurrence.seriesTime.getEndDate();
    }
    

    【讨论】:

    • I 不需要使用 getEndDate() 方法,因为值已经存在于对象中。只是因为 TypeScript 接口缺少无法获取 endYear、endMonth 和 endDay 值的属性。例如将 seriesTime 转换为 any: const s: any =recurrence.seriesTime;控制台.log(s.endYear);
      工作正常
    • SeriesTime 对象的属性值是内部值,名称可能会发生变化。面向公众的值是文档中定义的值:docs.microsoft.com/en-us/javascript/api/outlook/… 这些值不会更改(未经公告)。使用内部值可能会在没有通知的情况下破坏您的加载项。
    猜你喜欢
    • 1970-01-01
    • 2016-03-19
    • 1970-01-01
    • 2018-03-09
    • 1970-01-01
    • 2015-12-02
    • 2019-02-07
    • 2018-12-21
    • 1970-01-01
    相关资源
    最近更新 更多