Skip to content

Commit

Permalink
Improve integration of dom_types
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk authored and ry committed Sep 16, 2018
1 parent 4b1eb85 commit 0ef28be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 65 deletions.
2 changes: 1 addition & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ts_sources = [
"js/console.ts",
"js/deno.ts",
"js/dispatch.ts",
"js/dom_types.d.ts",
"js/dom_types.ts",
"js/errors.ts",
"js/fetch.ts",
"js/global-eval.ts",
Expand Down
2 changes: 0 additions & 2 deletions js/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import libEsnextIntlDts from "/third_party/node_modules/typescript/lib/lib.esnex
import libEsnextSymbolDts from "/third_party/node_modules/typescript/lib/lib.esnext.symbol.d.ts!string";

// Static definitions
import domTypesDts from "/js/dom_types.d.ts!string";
import flatbuffersDts from "/third_party/node_modules/@types/flatbuffers/index.d.ts!string";
import textEncodingDts from "/third_party/node_modules/@types/text-encoding/index.d.ts!string";
import typescriptDts from "/third_party/node_modules/typescript/lib/typescript.d.ts!string";
Expand Down Expand Up @@ -82,7 +81,6 @@ export const assetSourceCode: { [key: string]: string } = {
"lib.esnext.symbol.d.ts": libEsnextSymbolDts,

// Static definitions
"dom_types.d.ts": domTypesDts,
"flatbuffers.d.ts": flatbuffersDts,
"text-encoding.d.ts": textEncodingDts,
"typescript.d.ts": typescriptDts
Expand Down
81 changes: 19 additions & 62 deletions js/dom_types.d.ts → js/dom_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,39 @@ See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
*******************************************************************************/

type HeadersInit = string[][] | Record<string, string>;
export type HeadersInit = string[][] | Record<string, string>;
type BodyInit =
| Blob
| BufferSource
| FormData
| URLSearchParams
| ReadableStream
| string;
type RequestInfo = Request | string;
export type RequestInfo = Request | string;
type ReferrerPolicy =
| ""
| "no-referrer"
| "no-referrer-when-downgrade"
| "origin-only"
| "origin-when-cross-origin"
| "unsafe-url";
type BlobPart = BufferSource | Blob | string;
export type BlobPart = BufferSource | Blob | string;
type FormDataEntryValue = File | string;
declare type EventListenerOrEventListenerObject =
export type EventListenerOrEventListenerObject =
| EventListener
| EventListenerObject;

interface Element {
// TODO
}

interface HTMLFormElement {
export interface HTMLFormElement {
// TODO
}

type EndingType = "tranparent" | "native";

interface BlobPropertyBag {
export interface BlobPropertyBag {
type?: string;
ending?: EndingType;
}
Expand All @@ -68,7 +68,7 @@ interface EventTarget {
): void;
}

interface ProgressEventInit extends EventInit {
export interface ProgressEventInit extends EventInit {
lengthComputable?: boolean;
loaded?: number;
total?: number;
Expand Down Expand Up @@ -104,6 +104,7 @@ interface URLSearchParams {
sort(): void;
forEach(
callbackfn: (value: string, key: string, parent: URLSearchParams) => void,
// tslint:disable-next-line:no-any
thisArg?: any
): void;
}
Expand Down Expand Up @@ -148,12 +149,7 @@ interface File extends Blob {
readonly name: string;
}

declare var File: {
prototype: File;
new (fileBits: BlobPart[], fileName: string, options?: FilePropertyBag): File;
};

interface FilePropertyBag extends BlobPropertyBag {
export interface FilePropertyBag extends BlobPropertyBag {
lastModified?: number;
}

Expand All @@ -163,11 +159,6 @@ interface ProgressEvent extends Event {
readonly total: number;
}

declare var ProgressEvent: {
prototype: ProgressEvent;
new (type: string, eventInitDict?: ProgressEventInit): ProgressEvent;
};

interface EventListenerOptions {
capture?: boolean;
}
Expand All @@ -179,9 +170,11 @@ interface AddEventListenerOptions extends EventListenerOptions {

interface AbortSignal extends EventTarget {
readonly aborted: boolean;
// tslint:disable-next-line:no-any
onabort: ((this: AbortSignal, ev: ProgressEvent) => any) | null;
addEventListener<K extends keyof AbortSignalEventMap>(
type: K,
// tslint:disable-next-line:no-any
listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any,
options?: boolean | AddEventListenerOptions
): void;
Expand All @@ -192,6 +185,7 @@ interface AbortSignal extends EventTarget {
): void;
removeEventListener<K extends keyof AbortSignalEventMap>(
type: K,
// tslint:disable-next-line:no-any
listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any,
options?: boolean | EventListenerOptions
): void;
Expand All @@ -202,38 +196,24 @@ interface AbortSignal extends EventTarget {
): void;
}

declare var AbortSignal: {
prototype: AbortSignal;
new (): AbortSignal;
};

interface ReadableStream {
readonly locked: boolean;
cancel(): Promise<void>;
getReader(): ReadableStreamReader;
}

declare var ReadableStream: {
prototype: ReadableStream;
new (): ReadableStream;
};

interface EventListenerObject {
handleEvent(evt: Event): void;
}

interface ReadableStreamReader {
cancel(): Promise<void>;
// tslint:disable-next-line:no-any
read(): Promise<any>;
releaseLock(): void;
}

declare var ReadableStreamReader: {
prototype: ReadableStreamReader;
new (): ReadableStreamReader;
};

interface FormData {
export interface FormData {
append(name: string, value: string | Blob, fileName?: string): void;
delete(name: string): void;
get(name: string): FormDataEntryValue | null;
Expand All @@ -246,53 +226,41 @@ interface FormData {
key: string,
parent: FormData
) => void,
// tslint:disable-next-line:no-any
thisArg?: any
): void;
}

declare var FormData: {
prototype: FormData;
new (form?: HTMLFormElement): FormData;
};

export interface Blob {
readonly size: number;
readonly type: string;
slice(start?: number, end?: number, contentType?: string): Blob;
}

declare var Blob: {
prototype: Blob;
new (blobParts?: BlobPart[], options?: BlobPropertyBag): Blob;
};

interface Body {
readonly body: ReadableStream | null;
readonly bodyUsed: boolean;
arrayBuffer(): Promise<ArrayBuffer>;
blob(): Promise<Blob>;
formData(): Promise<FormData>;
// tslint:disable-next-line:no-any
json(): Promise<any>;
text(): Promise<string>;
}

interface Headers {
export interface Headers {
append(name: string, value: string): void;
delete(name: string): void;
get(name: string): string | null;
has(name: string): boolean;
set(name: string, value: string): void;
forEach(
callbackfn: (value: string, key: string, parent: Headers) => void,
// tslint:disable-next-line:no-any
thisArg?: any
): void;
}

declare var Headers: {
prototype: Headers;
new (init?: HeadersInit): Headers;
};

type RequestCache =
| "default"
| "no-store"
Expand Down Expand Up @@ -343,6 +311,7 @@ export interface RequestInit {
referrer?: string;
referrerPolicy?: ReferrerPolicy;
signal?: AbortSignal | null;
// tslint:disable-next-line:no-any
window?: any;
}

Expand Down Expand Up @@ -439,11 +408,6 @@ export interface Request extends Body {
clone(): Request;
}

declare var Request: {
prototype: Request;
new (input: RequestInfo, init?: RequestInit): Request;
};

export interface Response extends Body {
readonly headers: Headers;
readonly ok: boolean;
Expand All @@ -455,10 +419,3 @@ export interface Response extends Body {
readonly url: string;
clone(): Response;
}

declare var Response: {
prototype: Response;
new (body?: BodyInit | null, init?: ResponseInit): Response;
error(): Response;
redirect(url: string, status?: number): Response;
};

0 comments on commit 0ef28be

Please sign in to comment.