diff --git a/baselines/dom.generated.d.ts b/baselines/dom.generated.d.ts index 7f3689998..6cb51f943 100644 --- a/baselines/dom.generated.d.ts +++ b/baselines/dom.generated.d.ts @@ -8312,13 +8312,13 @@ interface IDBCursor { * Delete the record pointed at by the cursor with a new value. * If successful, request's result will be undefined. */ - delete(): IDBRequest; + delete(): IDBRequest; /** * Updated the record pointed at by the cursor with a new value. * Throws a "DataError" DOMException if the effective object store uses in-line keys and the key would have changed. * If successful, request's result will be the record's key. */ - update(value: any): IDBRequest; + update(value: any): IDBRequest; } declare var IDBCursor: { @@ -8444,40 +8444,40 @@ interface IDBIndex { * If successful, request's result will be the * count. */ - count(key?: IDBValidKey | IDBKeyRange): IDBRequest; + count(key?: IDBValidKey | IDBKeyRange): IDBRequest; /** * Retrieves the value of the first record matching the * given key or key range in query. * If successful, request's result will be the value, or undefined if there was no matching record. */ - get(key: IDBValidKey | IDBKeyRange): IDBRequest; + get(key: IDBValidKey | IDBKeyRange): IDBRequest; /** * Retrieves the values of the records matching the given key or key range in query (up to count if given). * If successful, request's result will be an Array of the values. */ - getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest; + getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest; /** * Retrieves the keys of records matching the given key or key range in query (up to count if given). * If successful, request's result will be an Array of the keys. */ - getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest; + getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest; /** * Retrieves the key of the first record matching the * given key or key range in query. * If successful, request's result will be the key, or undefined if there was no matching record. */ - getKey(key: IDBValidKey | IDBKeyRange): IDBRequest; + getKey(key: IDBValidKey | IDBKeyRange): IDBRequest; /** * Opens a cursor over the records matching query, * ordered by direction. If query is null, all records in index are matched. * If successful, request's result will be an IDBCursorWithValue, or null if there were no matching records. */ - openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest; + openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest; /** * Opens a cursor with key only flag set over the records matching query, ordered by direction. If query is null, all records in index are matched. * If successful, request's result will be an IDBCursor, or null if there were no matching records. */ - openKeyCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest; + openKeyCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest; } declare var IDBIndex: { @@ -8556,19 +8556,19 @@ interface IDBObjectStore { * Returns the associated transaction. */ readonly transaction: IDBTransaction; - add(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest; + add(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest; /** * Deletes all records in store. * If successful, request's result will * be undefined. */ - clear(): IDBRequest; + clear(): IDBRequest; /** * Retrieves the number of records matching the * given key or key range in query. * If successful, request's result will be the count. */ - count(key?: IDBValidKey | IDBKeyRange): IDBRequest; + count(key?: IDBValidKey | IDBKeyRange): IDBRequest; /** * Creates a new index in store with the given name, keyPath and options and returns a new IDBIndex. If the keyPath and options define constraints that cannot be * satisfied with the data already in store the upgrade @@ -8583,7 +8583,7 @@ interface IDBObjectStore { * If successful, request's result will * be undefined. */ - delete(key: IDBValidKey | IDBKeyRange): IDBRequest; + delete(key: IDBValidKey | IDBKeyRange): IDBRequest; /** * Deletes the index in store with the given name. * Throws an "InvalidStateError" DOMException if not called within an upgrade @@ -8595,41 +8595,41 @@ interface IDBObjectStore { * given key or key range in query. * If successful, request's result will be the value, or undefined if there was no matching record. */ - get(query: IDBValidKey | IDBKeyRange): IDBRequest; + get(query: IDBValidKey | IDBKeyRange): IDBRequest; /** * Retrieves the values of the records matching the * given key or key range in query (up to count if given). * If successful, request's result will * be an Array of the values. */ - getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest; + getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest; /** * Retrieves the keys of records matching the * given key or key range in query (up to count if given). * If successful, request's result will * be an Array of the keys. */ - getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest; + getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest; /** * Retrieves the key of the first record matching the * given key or key range in query. * If successful, request's result will be the key, or undefined if there was no matching record. */ - getKey(query: IDBValidKey | IDBKeyRange): IDBRequest; + getKey(query: IDBValidKey | IDBKeyRange): IDBRequest; index(name: string): IDBIndex; /** * Opens a cursor over the records matching query, * ordered by direction. If query is null, all records in store are matched. * If successful, request's result will be an IDBCursorWithValue pointing at the first matching record, or null if there were no matching records. */ - openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest; + openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest; /** * Opens a cursor with key only flag set over the records matching query, ordered by direction. If query is null, all records in store are matched. * If successful, request's result will be an IDBCursor pointing at the first matching record, or * null if there were no matching records. */ - openKeyCursor(query?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest; - put(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest; + openKeyCursor(query?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest; + put(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest; } declare var IDBObjectStore: { @@ -8642,7 +8642,7 @@ interface IDBOpenDBRequestEventMap extends IDBRequestEventMap { "upgradeneeded": IDBVersionChangeEvent; } -interface IDBOpenDBRequest extends IDBRequest { +interface IDBOpenDBRequest extends IDBRequest { onblocked: ((this: IDBOpenDBRequest, ev: Event) => any) | null; onupgradeneeded: ((this: IDBOpenDBRequest, ev: IDBVersionChangeEvent) => any) | null; addEventListener(type: K, listener: (this: IDBOpenDBRequest, ev: IDBOpenDBRequestEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; @@ -8661,14 +8661,14 @@ interface IDBRequestEventMap { "success": Event; } -interface IDBRequest extends EventTarget { +interface IDBRequest extends EventTarget { /** * When a request is completed, returns the error (a DOMException), or null if the request succeeded. Throws * a "InvalidStateError" DOMException if the request is still pending. */ readonly error: DOMException | null; - onerror: ((this: IDBRequest, ev: Event) => any) | null; - onsuccess: ((this: IDBRequest, ev: Event) => any) | null; + onerror: ((this: IDBRequest, ev: Event) => any) | null; + onsuccess: ((this: IDBRequest, ev: Event) => any) | null; /** * Returns "pending" until a request is complete, * then returns "done". @@ -8679,7 +8679,7 @@ interface IDBRequest extends EventTarget { * or undefined if the request failed. Throws a * "InvalidStateError" DOMException if the request is still pending. */ - readonly result: any; + readonly result: T; /** * Returns the IDBObjectStore, IDBIndex, or IDBCursor the request was made against, or null if is was an open * request. @@ -8690,9 +8690,9 @@ interface IDBRequest extends EventTarget { * If this as an open request, then it returns an upgrade transaction while it is running, or null otherwise. */ readonly transaction: IDBTransaction | null; - addEventListener(type: K, listener: (this: IDBRequest, ev: IDBRequestEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; + addEventListener(type: K, listener: (this: IDBRequest, ev: IDBRequestEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; - removeEventListener(type: K, listener: (this: IDBRequest, ev: IDBRequestEventMap[K]) => any, options?: boolean | EventListenerOptions): void; + removeEventListener(type: K, listener: (this: IDBRequest, ev: IDBRequestEventMap[K]) => any, options?: boolean | EventListenerOptions): void; removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; } @@ -17043,4 +17043,4 @@ type VRDisplayEventReason = "mounted" | "navigation" | "requested" | "unmounted" type VideoFacingModeEnum = "user" | "environment" | "left" | "right"; type VisibilityState = "hidden" | "visible" | "prerender"; type WorkerType = "classic" | "module"; -type XMLHttpRequestResponseType = "" | "arraybuffer" | "blob" | "document" | "json" | "text"; \ No newline at end of file +type XMLHttpRequestResponseType = "" | "arraybuffer" | "blob" | "document" | "json" | "text"; diff --git a/baselines/webworker.generated.d.ts b/baselines/webworker.generated.d.ts index 20fc29eea..e061bac6e 100644 --- a/baselines/webworker.generated.d.ts +++ b/baselines/webworker.generated.d.ts @@ -1095,13 +1095,13 @@ interface IDBCursor { * Delete the record pointed at by the cursor with a new value. * If successful, request's result will be undefined. */ - delete(): IDBRequest; + delete(): IDBRequest; /** * Updated the record pointed at by the cursor with a new value. * Throws a "DataError" DOMException if the effective object store uses in-line keys and the key would have changed. * If successful, request's result will be the record's key. */ - update(value: any): IDBRequest; + update(value: any): IDBRequest; } declare var IDBCursor: { @@ -1223,40 +1223,40 @@ interface IDBIndex { * If successful, request's result will be the * count. */ - count(key?: IDBValidKey | IDBKeyRange): IDBRequest; + count(key?: IDBValidKey | IDBKeyRange): IDBRequest; /** * Retrieves the value of the first record matching the * given key or key range in query. * If successful, request's result will be the value, or undefined if there was no matching record. */ - get(key: IDBValidKey | IDBKeyRange): IDBRequest; + get(key: IDBValidKey | IDBKeyRange): IDBRequest; /** * Retrieves the values of the records matching the given key or key range in query (up to count if given). * If successful, request's result will be an Array of the values. */ - getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest; + getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest; /** * Retrieves the keys of records matching the given key or key range in query (up to count if given). * If successful, request's result will be an Array of the keys. */ - getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest; + getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest; /** * Retrieves the key of the first record matching the * given key or key range in query. * If successful, request's result will be the key, or undefined if there was no matching record. */ - getKey(key: IDBValidKey | IDBKeyRange): IDBRequest; + getKey(key: IDBValidKey | IDBKeyRange): IDBRequest; /** * Opens a cursor over the records matching query, * ordered by direction. If query is null, all records in index are matched. * If successful, request's result will be an IDBCursorWithValue, or null if there were no matching records. */ - openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest; + openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest; /** * Opens a cursor with key only flag set over the records matching query, ordered by direction. If query is null, all records in index are matched. * If successful, request's result will be an IDBCursor, or null if there were no matching records. */ - openKeyCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest; + openKeyCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest; } declare var IDBIndex: { @@ -1335,19 +1335,19 @@ interface IDBObjectStore { * Returns the associated transaction. */ readonly transaction: IDBTransaction; - add(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest; + add(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest; /** * Deletes all records in store. * If successful, request's result will * be undefined. */ - clear(): IDBRequest; + clear(): IDBRequest; /** * Retrieves the number of records matching the * given key or key range in query. * If successful, request's result will be the count. */ - count(key?: IDBValidKey | IDBKeyRange): IDBRequest; + count(key?: IDBValidKey | IDBKeyRange): IDBRequest; /** * Creates a new index in store with the given name, keyPath and options and returns a new IDBIndex. If the keyPath and options define constraints that cannot be * satisfied with the data already in store the upgrade @@ -1362,7 +1362,7 @@ interface IDBObjectStore { * If successful, request's result will * be undefined. */ - delete(key: IDBValidKey | IDBKeyRange): IDBRequest; + delete(key: IDBValidKey | IDBKeyRange): IDBRequest; /** * Deletes the index in store with the given name. * Throws an "InvalidStateError" DOMException if not called within an upgrade @@ -1374,41 +1374,41 @@ interface IDBObjectStore { * given key or key range in query. * If successful, request's result will be the value, or undefined if there was no matching record. */ - get(query: IDBValidKey | IDBKeyRange): IDBRequest; + get(query: IDBValidKey | IDBKeyRange): IDBRequest; /** * Retrieves the values of the records matching the * given key or key range in query (up to count if given). * If successful, request's result will * be an Array of the values. */ - getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest; + getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest; /** * Retrieves the keys of records matching the * given key or key range in query (up to count if given). * If successful, request's result will * be an Array of the keys. */ - getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest; + getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest; /** * Retrieves the key of the first record matching the * given key or key range in query. * If successful, request's result will be the key, or undefined if there was no matching record. */ - getKey(query: IDBValidKey | IDBKeyRange): IDBRequest; + getKey(query: IDBValidKey | IDBKeyRange): IDBRequest; index(name: string): IDBIndex; /** * Opens a cursor over the records matching query, * ordered by direction. If query is null, all records in store are matched. * If successful, request's result will be an IDBCursorWithValue pointing at the first matching record, or null if there were no matching records. */ - openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest; + openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest; /** * Opens a cursor with key only flag set over the records matching query, ordered by direction. If query is null, all records in store are matched. * If successful, request's result will be an IDBCursor pointing at the first matching record, or * null if there were no matching records. */ - openKeyCursor(query?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest; - put(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest; + openKeyCursor(query?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest; + put(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest; } declare var IDBObjectStore: { @@ -1421,7 +1421,7 @@ interface IDBOpenDBRequestEventMap extends IDBRequestEventMap { "upgradeneeded": IDBVersionChangeEvent; } -interface IDBOpenDBRequest extends IDBRequest { +interface IDBOpenDBRequest extends IDBRequest { onblocked: ((this: IDBOpenDBRequest, ev: Event) => any) | null; onupgradeneeded: ((this: IDBOpenDBRequest, ev: IDBVersionChangeEvent) => any) | null; addEventListener(type: K, listener: (this: IDBOpenDBRequest, ev: IDBOpenDBRequestEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; @@ -1440,14 +1440,14 @@ interface IDBRequestEventMap { "success": Event; } -interface IDBRequest extends EventTarget { +interface IDBRequest extends EventTarget { /** * When a request is completed, returns the error (a DOMException), or null if the request succeeded. Throws * a "InvalidStateError" DOMException if the request is still pending. */ readonly error: DOMException | null; - onerror: ((this: IDBRequest, ev: Event) => any) | null; - onsuccess: ((this: IDBRequest, ev: Event) => any) | null; + onerror: ((this: IDBRequest, ev: Event) => any) | null; + onsuccess: ((this: IDBRequest, ev: Event) => any) | null; /** * Returns "pending" until a request is complete, * then returns "done". @@ -1458,7 +1458,7 @@ interface IDBRequest extends EventTarget { * or undefined if the request failed. Throws a * "InvalidStateError" DOMException if the request is still pending. */ - readonly result: any; + readonly result: T; /** * Returns the IDBObjectStore, IDBIndex, or IDBCursor the request was made against, or null if is was an open * request. @@ -1469,9 +1469,9 @@ interface IDBRequest extends EventTarget { * If this as an open request, then it returns an upgrade transaction while it is running, or null otherwise. */ readonly transaction: IDBTransaction | null; - addEventListener(type: K, listener: (this: IDBRequest, ev: IDBRequestEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; + addEventListener(type: K, listener: (this: IDBRequest, ev: IDBRequestEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; - removeEventListener(type: K, listener: (this: IDBRequest, ev: IDBRequestEventMap[K]) => any, options?: boolean | EventListenerOptions): void; + removeEventListener(type: K, listener: (this: IDBRequest, ev: IDBRequestEventMap[K]) => any, options?: boolean | EventListenerOptions): void; removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; } @@ -2727,4 +2727,4 @@ type ServiceWorkerState = "installing" | "installed" | "activating" | "activated type ServiceWorkerUpdateViaCache = "imports" | "all" | "none"; type VisibilityState = "hidden" | "visible" | "prerender"; type WorkerType = "classic" | "module"; -type XMLHttpRequestResponseType = "" | "arraybuffer" | "blob" | "document" | "json" | "text"; \ No newline at end of file +type XMLHttpRequestResponseType = "" | "arraybuffer" | "blob" | "document" | "json" | "text"; diff --git a/inputfiles/addedTypes.json b/inputfiles/addedTypes.json index 96bf70afe..c80268aaf 100644 --- a/inputfiles/addedTypes.json +++ b/inputfiles/addedTypes.json @@ -715,6 +715,7 @@ }, "IDBOpenDBRequest": { "name": "IDBOpenDBRequest", + "extends": "IDBRequest", "events": { "event": [ { diff --git a/inputfiles/overridingTypes.json b/inputfiles/overridingTypes.json index 7705ee0d7..a17e92980 100644 --- a/inputfiles/overridingTypes.json +++ b/inputfiles/overridingTypes.json @@ -224,7 +224,10 @@ } }, "type-parameters": [ - "T = any" + { + "name": "T", + "default": "any" + } ], "constructor": { "override-signatures": [ @@ -454,61 +457,67 @@ "openCursor": { "name": "openCursor", "override-signatures": [ - "openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest" + "openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest" ] }, "openKeyCursor": { "name": "openKeyCursor", "override-signatures": [ - "openKeyCursor(query?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest" + "openKeyCursor(query?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest" ] }, "add": { "name": "add", "override-signatures": [ - "add(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest" + "add(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest" + ] + }, + "clear": { + "name": "clear", + "override-signatures": [ + "clear(): IDBRequest" ] }, "count": { "name": "count", "override-signatures": [ - "count(key?: IDBValidKey | IDBKeyRange): IDBRequest" + "count(key?: IDBValidKey | IDBKeyRange): IDBRequest" ] }, "delete": { "name": "delete", "override-signatures": [ - "delete(key: IDBValidKey | IDBKeyRange): IDBRequest" + "delete(key: IDBValidKey | IDBKeyRange): IDBRequest" ] }, "put": { "name": "put", "override-signatures": [ - "put(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest" + "put(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest" ] }, "get": { "name": "get", "override-signatures": [ - "get(query: IDBValidKey | IDBKeyRange): IDBRequest" + "get(query: IDBValidKey | IDBKeyRange): IDBRequest" ] }, "getAll": { "name": "getAll", "override-signatures": [ - "getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest" + "getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest" ] }, "getAllKeys": { "name": "getAllKeys", "override-signatures": [ - "getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest" + "getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest" ] }, "getKey": { "name": "getKey", "override-signatures": [ - "getKey(query: IDBValidKey | IDBKeyRange): IDBRequest" + "getKey(query: IDBValidKey | IDBKeyRange): IDBRequest" ] } } @@ -554,43 +563,43 @@ "openCursor": { "name": "openCursor", "override-signatures": [ - "openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest" + "openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest" ] }, "openKeyCursor": { "name": "openKeyCursor", "override-signatures": [ - "openKeyCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest" + "openKeyCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest" ] }, "count": { "name": "count", "override-signatures": [ - "count(key?: IDBValidKey | IDBKeyRange): IDBRequest" + "count(key?: IDBValidKey | IDBKeyRange): IDBRequest" ] }, "get": { "name": "get", "override-signatures": [ - "get(key: IDBValidKey | IDBKeyRange): IDBRequest" + "get(key: IDBValidKey | IDBKeyRange): IDBRequest" ] }, "getAll": { "name": "getAll", "override-signatures": [ - "getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest" + "getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest" ] }, "getAllKeys": { "name": "getAllKeys", "override-signatures": [ - "getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest" + "getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest" ] }, "getKey": { "name": "getKey", "override-signatures": [ - "getKey(key: IDBValidKey | IDBKeyRange): IDBRequest" + "getKey(key: IDBValidKey | IDBKeyRange): IDBRequest" ] } } @@ -1183,6 +1192,16 @@ "override-signatures": [ "continuePrimaryKey(key: IDBValidKey | IDBKeyRange, primaryKey: IDBValidKey | IDBKeyRange): void" ] + }, + "delete": { + "override-signatures": [ + "delete(): IDBRequest" + ] + }, + "update": { + "override-signatures": [ + "update(value: any): IDBRequest" + ] } } } @@ -1200,9 +1219,19 @@ "name": "source", "nullable": false, "override-type": "IDBObjectStore | IDBIndex | IDBCursor" + }, + "result": { + "name": "result", + "override-type": "T" } } - } + }, + "type-parameters": [ + { + "name": "T", + "default": "any" + } + ] }, "IDBTransaction": { "name": "IDBTransaction", @@ -2315,7 +2344,10 @@ } }, "type-parameters": [ - "T = any" + { + "name": "T", + "default": "any" + } ] }, "AesGcmParams": { diff --git a/package-lock.json b/package-lock.json index 26c791cf6..81aab6dd8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -307,6 +307,11 @@ "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, + "diff": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-1.4.0.tgz", + "integrity": "sha1-fyjS657nsVqX79ic5j3P2qPMur8=" + }, "domexception": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/domexception/-/domexception-1.0.1.tgz", @@ -1385,6 +1390,14 @@ "resolved": "https://registry.npmjs.org/preserve/-/preserve-0.2.0.tgz", "integrity": "sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks=" }, + "print-diff": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/print-diff/-/print-diff-0.1.1.tgz", + "integrity": "sha512-dp36GezMEivgKH/zcLB4eBhJmQM3ewAa1UAqEPXMzU69NQ5wCP8puVBZlDFyt1WEtR5k2UC+3ahg+T5BfmRVGw==", + "requires": { + "diff": "^1.2.1" + } + }, "process-nextick-args": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", diff --git a/package.json b/package.json index 7210c6db7..6ba0eafef 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "cpx": "^1.5.0", "jsdom": "^11.11.0", "node-fetch": "^2.1.1", + "print-diff": "^0.1.1", "typescript": "next", "webidl2": "^13.0.2" } diff --git a/src/emitter.ts b/src/emitter.ts index 5b2fe7c90..809bb7d73 100644 --- a/src/emitter.ts +++ b/src/emitter.ts @@ -82,11 +82,9 @@ function createTextWriter(newLine: string) { stack = []; } - function writeLine() { - if (!lineStart) { - output += newLine; - lineStart = true; - } + function endLine() { + output += newLine; + lineStart = true; } reset(); @@ -98,8 +96,9 @@ function createTextWriter(newLine: string) { increaseIndent() { indent++; }, decreaseIndent() { indent--; }, + endLine: endLine, print: write, - printLine(c: string) { writeLine(); write(c); }, + printLine(c: string) { write(c); endLine(); }, clearStack() { stack = []; }, stackIsEmpty() { return stack.length === 0; }, @@ -226,7 +225,8 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) { return ehParents; } - const parentWithEventHandler = allInterfacesMap[i.extends] && getParentEventHandler(allInterfacesMap[i.extends]) || []; + const iExtends = i.extends && i.extends.replace(/<.*>$/, ''); + const parentWithEventHandler = allInterfacesMap[iExtends] && getParentEventHandler(allInterfacesMap[iExtends]) || []; const mixinsWithEventHandler = flatMap(i.implements || [], i => getParentEventHandler(allInterfacesMap[i])); return distinct(parentWithEventHandler.concat(mixinsWithEventHandler)); @@ -356,6 +356,15 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) { return obj.nullable ? makeNullable(resolvedType) : resolvedType; } + function nameWithForwardedTypes (i: Browser.Interface) { + const typeParameters = i["type-parameters"]; + + if (!typeParameters) return i.name; + if (!typeParameters.length) return i.name; + + return `${i.name}<${typeParameters.map(t => t.name)}>`; + } + function emitConstant(c: Browser.Constant) { printer.printLine(`readonly ${c.name}: ${convertDomTypeToTsType(c)};`); } @@ -377,7 +386,11 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) { } function processInterfaceType(i: Browser.Interface | Browser.Dictionary, name: string) { - return i["type-parameters"] ? name + "<" + i["type-parameters"]!.join(", ") + ">" : name; + function typeParameterWithDefault (type: Browser.TypeParameter) { + return type.default ? type.name + " = " + type.default : type.name + } + + return i["type-parameters"] ? name + "<" + i["type-parameters"]!.map(typeParameterWithDefault).join(", ") + ">" : name; } /// Emit overloads for the createElement method @@ -536,7 +549,7 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) { function emitEventHandlerThis(prefix: string, i: Browser.Interface) { if (prefix === "") { - return `this: ${i.name}, `; + return `this: ${nameWithForwardedTypes(i)}, `; } else { return pollutor ? `this: ${pollutor.name}, ` : ""; @@ -723,7 +736,7 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) { return; function emitTypedEventHandler(prefix: string, addOrRemove: string, iParent: Browser.Interface, optionsType: string) { - printer.printLine(`${prefix}${addOrRemove}EventListener(type: K, listener: (this: ${i.name}, ev: ${iParent.name}EventMap[K]) => any, options?: boolean | ${optionsType}): void;`); + printer.printLine(`${prefix}${addOrRemove}EventListener(type: K, listener: (this: ${nameWithForwardedTypes(i)}, ev: ${iParent.name}EventMap[K]) => any, options?: boolean | ${optionsType}): void;`); } function tryEmitTypedEventHandlerForInterface(addOrRemove: string, optionsType: string) { @@ -811,7 +824,7 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) { printer.printLineToStack(`interface ${processInterfaceType(i, i.name)} extends ${processedIName} {`); } - printer.printLine(`interface ${processInterfaceType(i, processedIName)}`); + printer.print(`interface ${processInterfaceType(i, processedIName)}`); const finalExtends = distinct([i.extends || "Object"].concat(i.implements || []) .filter(i => i !== "Object") @@ -821,6 +834,7 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) { printer.print(` extends ${finalExtends.join(", ")}`); } printer.print(" {"); + printer.endLine(); } /// To decide if a given method is an indexer and should be emited @@ -881,12 +895,13 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) { const ehParentCount = iNameToEhParents[i.name] && iNameToEhParents[i.name].length; if (hasEventHandlers || ehParentCount > 1) { - printer.printLine(`interface ${i.name}EventMap`); + printer.print(`interface ${i.name}EventMap`); if (ehParentCount) { const extend = iNameToEhParents[i.name].map(i => i.name + "EventMap"); printer.print(` extends ${extend.join(", ")}`); } printer.print(" {"); + printer.endLine(); printer.increaseIndent(); iNameToEhList[i.name] .sort(compareName) @@ -1170,6 +1185,7 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) { if (subtypes) { const iteratorExtends = getIteratorExtends(i.iterator, subtypes); const name = extendConflictsBaseTypes[i.name] ? `${i.name}Base` : i.name; + printer.printLine(""); printer.printLine(`interface ${name} ${iteratorExtends}{`); printer.increaseIndent(); if (!iteratorExtends) { @@ -1180,7 +1196,6 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) { } printer.decreaseIndent(); printer.printLine("}"); - printer.printLine(""); } } @@ -1189,7 +1204,6 @@ export function emitWebIDl(webidl: Browser.WebIdl, flavor: Flavor) { printer.printLine("/////////////////////////////"); printer.printLine("/// DOM Iterable APIs"); printer.printLine("/////////////////////////////"); - printer.printLine(""); allInterfaces .sort(compareName) diff --git a/src/test.ts b/src/test.ts index b6efa9cf0..21e725b25 100644 --- a/src/test.ts +++ b/src/test.ts @@ -1,6 +1,7 @@ import * as fs from "fs"; import * as path from "path"; import child_process from "child_process"; +import printDiff = require("print-diff"); const __SOURCE_DIRECTORY__ = __dirname; const baselineFolder = path.join(__SOURCE_DIRECTORY__, "../", "baselines"); @@ -17,6 +18,7 @@ function compareToBaselines() { const generated = normalizeLineEndings(fs.readFileSync(path.join(outputFolder, file)).toString()); if (baseline !== generated) { console.error(`Test failed: '${file}' is different from baseline file.`); + printDiff(generated, baseline); return false; } } diff --git a/src/types.d.ts b/src/types.d.ts index 54128103c..0d1543b11 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -138,6 +138,11 @@ export interface Element { specs?: string; } +export interface TypeParameter { + name: string; + default?: string; +} + export interface Interface { name: string; extends: string; @@ -173,7 +178,7 @@ export interface Interface { "primary-global"?: string; "no-interface-object"?: 1; global?: string; - "type-parameters"?: string[]; + "type-parameters"?: TypeParameter[]; "override-index-signatures"?: string[]; specs?: string; iterable?: "value" | "pair" | "pair-iterator"; @@ -207,7 +212,7 @@ export interface Dictionary { member: Record; } specs?: string; - "type-parameters"?: string[]; + "type-parameters"?: TypeParameter[]; } export interface WebIdl {