Add types for ical (#39198)

* start ical types (external deps?)

* rework calendar component types

* add tests

* fix name

* fix callback return type

* optional index signature

* comment
This commit is contained in:
Nick Clifford 2019-10-22 16:40:00 -05:00 committed by Wesley Wigham
parent 65a9a348d0
commit 921c7103a4
5 changed files with 114 additions and 0 deletions

21
types/ical/ical-tests.ts Normal file
View File

@ -0,0 +1,21 @@
import * as ical from 'ical';
const calendar: ical.FullCalendar = ical.parseFile('cal.ics');
const event: ical.CalendarComponent = calendar['uid'];
// $ExpectType CalendarComponentType
event.type;
// $ExpectType string | undefined
event.summary;
// $ExpectType Date | undefined
event.start;
// $ExpectType Geo | undefined
event.geo;
// $ExpectType string[] | undefined
event.categories;
// $ExpectType CalendarComponent[] | undefined
event.recurrences;
// $ExpectType FreeBusy | undefined
event.freebusy;
// $ExpectType string | ParamList | undefined
event.sequence;

63
types/ical/index.d.ts vendored Normal file
View File

@ -0,0 +1,63 @@
// Type definitions for ical 0.6
// Project: https://github.com/peterbraden/ical.js
// Definitions by: Nick Clifford <https://github.com/nickbclifford>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import request = require('request');
import { RRule } from 'rrule';
export type CalendarComponentType = 'VEVENT' | 'VTODO' | 'VJOURNAL' | 'VFREEBUSY' | 'VTIMEZONE' | 'VALARM';
export interface ParamList {
params: { [key: string]: string };
val: string;
}
export type FreeBusyType = 'FREE' | 'BUSY';
export interface FreeBusy {
type: FreeBusyType;
start: Date;
end: Date;
}
// All properties (except type) are optional
// Typed as string | ParamList by default, exceptions listed below
export type CalendarComponent = {
type: CalendarComponentType;
summary?: string;
description?: string;
url?: string;
uid?: string;
location?: string;
start?: Date;
end?: Date;
rrule?: RRule;
exdate?: { [datestr: string]: Date };
recurrences?: CalendarComponent[];
class?: string;
transparency?: string;
geo?: Geo;
completion?: string;
completed?: Date;
categories?: string[];
freebusy?: FreeBusy;
dtstamp?: Date;
created?: Date;
lastmodified?: Date;
recurrenceid?: Date;
} & { [prop: string]: string | ParamList | undefined };
export interface Geo {
lat: number;
long: number;
}
export interface FullCalendar {
[uid: string]: CalendarComponent;
}
export function parseICS(icsData: string): FullCalendar;
export function parseFile(filename: string): FullCalendar;
export function fromURL(url: string, options: request.CoreOptions, callback: (error: any, data: FullCalendar) => void): void;

6
types/ical/package.json Normal file
View File

@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"rrule": ">=2.3.0"
}
}

23
types/ical/tsconfig.json Normal file
View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"ical-tests.ts"
]
}

1
types/ical/tslint.json Normal file
View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }