参数不接受订单:"开始时间"?



嗨,我正在使用Google API在打字稿中编写一个AngularJS,试图打电话以获取Google Calendar Events,该语法在文档中定义:https://developers.google.com/Google-apps/verentar/v3/参考/事件/列表但是由于某种原因gapi.client.calendar.events.list(params)

不接受参数orderBy: 'startTime'

getCalendarEvents() {
    return gapi.client.calendar.calendarList.list().then(response => {
        let calendars = response.result.items;
        if (calendars === undefined) return [];
        console.log(calendars);
        let requests = calendars.map(calendar => {
            //let params = { calendarId: calendar.id, timeMin: (new Date()).toISOString(), showDeleted: false, singleEvents: true, maxResults: 10 };
            let params = { 
                calendarId: calendar.id, 
                timeMin: (new Date()).toISOString(), 
                showDeleted: false, 
                singleEvents: true, 
                orderBy: 'startTime' };
            return gapi.client.calendar.events.list(params).then(response => {
                console.log(response.result.items);
                let events: any = response.result.items.sort((a, b) => { // sorting array of events by date
                    if (a.start.date) a.start['newdate'] = a.start.date;
                    if (b.start.date) b.start['newdate'] = b.start.date;
                    if (a.start.dateTime) a.start['newdate'] = a.start.dateTime.slice(0, 10);
                    if (b.start.dateTime) b.start['newdate'] = b.start.dateTime.slice(0, 10);
                    if (a.start['newdate'] > b.start['newdate']) return 1;
                    if (a.start['newdate'] < b.start['newdate']) return -1;
                    return 0;
                });
                return events.map(event => {
                    let calendarEvent: CalendarEvent = {
                        title: event.summary,
                        htmlLink: event.htmlLink,
                        start: new Date(event.start.date == undefined ? event.start.dateTime == undefined ? '' : event.start.dateTime : event.start.date),
                        end: new Date(event.end.date == undefined ? event.end.dateTime == undefined ? '' : event.end.dateTime : event.end.date),
                        allDay: false,
                        color: calendar.backgroundColor
                    };
                    return calendarEvent;
                });
            });
        });
        return this.$q.all(requests);
    });
}

为什么这不起作用?

文件:'file:///d:/projects/homepage2/app/google.service.ts' 严重性:"错误"消息:'类型的参数'{calendarId:string; timemin:string;展示:布尔值;单个events:布尔值;Orderby: Stri ...'不能分配给类型的参数 " eventslistParameters"。财产的类型"订单"是 不相容。 键入'字符串'无法分配到键入'" starttime" |"更新" |不明确的'。'AT:'166,61'来源:'ts'

这样定义了参数:

  interface EventsListParameters {
    calendarId: string;
    alwaysIncludeEmail?: boolean;
    iCalUID?: string;
    maxAttendees?: integer;
    maxResults?: integer;
    orderBy?: EventsOrder;
    pageToken?: string;
    privateExtendedProperty?: string;
    q?: string;
    sharedExtendedProperty?: string;
    showDeleted?: boolean;
    showHiddenInvitations?: boolean;
    singleEvents?: boolean;
    syncToken?: SyncToken;
    timeMax?: datetime;
    timeMin?: datetime;
    timeZone?: string;
    updatedMin?: datetime;
  }

和eventerder的定义:

  type EventsOrder =
    // Order by the start date/time (ascending). This is only available when querying single events (i.e. the parameter singleEvents is True)
    'startTime' |
    // Order by last modification time (ascending).
    'updated';

fix

orderBy: 'startTime'更改为orderBy: 'startTime' as 'startTime'

更多

它被缩为字符串。在这里,我被用作断言,迫使它被推断出一个字面意思。

  • 类型上的文档https://basarat.gitbooks.io/typescript/docs/types/type-assertion.html
  • 这里提到的技巧https://basarat.gitbooks.io/typescript/docs/types/literal-types.html

相关内容

  • 没有找到相关文章

最新更新