Types for eventsource

This commit is contained in:
Scott Davis
2018-03-27 10:49:50 -07:00
parent 38bda769b6
commit ac7ab1c5c3
5 changed files with 105 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
import * as EventSource from "eventsource";
const eventSource = new EventSource("http://foobar");
eventSource.onmessage = (x: any) => {};
eventSource.onerror = (x: any) => {};
eventSource.onopen = (x: any) => {};
eventSource.close();
import * as EventSourcePolyfill from "eventsource/lib/eventsource-polyfill";
const eventSourcePolyfill = new EventSourcePolyfill("http://foobar");
eventSourcePolyfill.onmessage = (x: any) => {};
eventSourcePolyfill.onerror = (x: any) => {};
eventSourcePolyfill.onopen = (x: any) => {};
eventSourcePolyfill.close();

35
types/eventsource/index.d.ts vendored Normal file
View File

@@ -0,0 +1,35 @@
// Type definitions for eventsource 1.0
// Project: http://github.com/EventSource/eventsource
// Definitions by: Scott Lee Davis <https://github.com/scottleedavis>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
declare class EventSource {
constructor(url: string, eventSourceInitDict?: EventSource.EventSourceInitDict);
static CLOSED: EventSource.ReadyState;
static CONNECTING: EventSource.ReadyState;
static OPEN: EventSource.ReadyState;
url: string;
readyState: EventSource.ReadyState;
onopen: EventListener;
onmessage: EventListener;
onerror: EventListener;
close(): void;
}
declare namespace EventSource {
enum ReadyState {CONNECTING = 0, OPEN = 1, CLOSED = 2}
interface EventSourceInitDict {
withCredentials?: boolean;
headers?: object;
proxy?: string;
https?: object;
rejectUnauthorized?: boolean;
}
}
export = EventSource;
export as namespace EventSource;

View File

@@ -0,0 +1,29 @@
declare class EventSource {
constructor(url: string, eventSourceInitDict?: EventSource.EventSourceInitDict);
static CLOSED: EventSource.ReadyState;
static CONNECTING: EventSource.ReadyState;
static OPEN: EventSource.ReadyState;
url: string;
readyState: EventSource.ReadyState;
onopen: EventListener;
onmessage: EventListener;
onerror: EventListener;
close(): void;
}
declare namespace EventSource {
enum ReadyState {CONNECTING = 0, OPEN = 1, CLOSED = 2}
interface EventSourceInitDict {
withCredentials?: boolean;
headers?: object;
proxy?: string;
https?: object;
rejectUnauthorized?: boolean;
}
}
export = EventSource;
export as namespace EventSource;

View File

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

View File

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