Skip to content

Commit 34fc5cd

Browse files
committed
Type the result property on IDBRequest
1 parent b3b6c3b commit 34fc5cd

File tree

2 files changed

+58
-58
lines changed

2 files changed

+58
-58
lines changed

lib/lib.dom.d.ts

+29-29
Original file line numberDiff line numberDiff line change
@@ -8804,13 +8804,13 @@ interface IDBCursor {
88048804
* Delete the record pointed at by the cursor with a new value.
88058805
* If successful, request's result will be undefined.
88068806
*/
8807-
delete(): IDBRequest;
8807+
delete(): IDBRequest<void>;
88088808
/**
88098809
* Updated the record pointed at by the cursor with a new value.
88108810
* Throws a "DataError" DOMException if the effective object store uses in-line keys and the key would have changed.
88118811
* If successful, request's result will be the record's key.
88128812
*/
8813-
update(value: any): IDBRequest;
8813+
update(value: any): IDBRequest<IDBValidKey>;
88148814
}
88158815

88168816
declare var IDBCursor: {
@@ -8936,40 +8936,40 @@ interface IDBIndex {
89368936
* If successful, request's result will be the
89378937
* count.
89388938
*/
8939-
count(key?: IDBValidKey | IDBKeyRange): IDBRequest;
8939+
count(key?: IDBValidKey | IDBKeyRange): IDBRequest<number>;
89408940
/**
89418941
* Retrieves the value of the first record matching the
89428942
* given key or key range in query.
89438943
* If successful, request's result will be the value, or undefined if there was no matching record.
89448944
*/
8945-
get(key: IDBValidKey | IDBKeyRange): IDBRequest;
8945+
get(key: IDBValidKey | IDBKeyRange): IDBRequest<IDBValue>;
89468946
/**
89478947
* Retrieves the values of the records matching the given key or key range in query (up to count if given).
89488948
* If successful, request's result will be an Array of the values.
89498949
*/
8950-
getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest;
8950+
getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest<any[]>;
89518951
/**
89528952
* Retrieves the keys of records matching the given key or key range in query (up to count if given).
89538953
* If successful, request's result will be an Array of the keys.
89548954
*/
8955-
getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest;
8955+
getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest<IDBValidKey[]>;
89568956
/**
89578957
* Retrieves the key of the first record matching the
89588958
* given key or key range in query.
89598959
* If successful, request's result will be the key, or undefined if there was no matching record.
89608960
*/
8961-
getKey(key: IDBValidKey | IDBKeyRange): IDBRequest;
8961+
getKey(key: IDBValidKey | IDBKeyRange): IDBRequest<IDBValidKey | undefined>;
89628962
/**
89638963
* Opens a cursor over the records matching query,
89648964
* ordered by direction. If query is null, all records in index are matched.
89658965
* If successful, request's result will be an IDBCursorWithValue, or null if there were no matching records.
89668966
*/
8967-
openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest;
8967+
openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest<IDBCursorWithValue | null>;
89688968
/**
89698969
* 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.
89708970
* If successful, request's result will be an IDBCursor, or null if there were no matching records.
89718971
*/
8972-
openKeyCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest;
8972+
openKeyCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest<IDBCursor | null>;
89738973
}
89748974

89758975
declare var IDBIndex: {
@@ -9048,19 +9048,19 @@ interface IDBObjectStore {
90489048
* Returns the associated transaction.
90499049
*/
90509050
readonly transaction: IDBTransaction;
9051-
add(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest;
9051+
add(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest<any>;
90529052
/**
90539053
* Deletes all records in store.
90549054
* If successful, request's result will
90559055
* be undefined.
90569056
*/
9057-
clear(): IDBRequest;
9057+
clear(): IDBRequest<undefined>;
90589058
/**
90599059
* Retrieves the number of records matching the
90609060
* given key or key range in query.
90619061
* If successful, request's result will be the count.
90629062
*/
9063-
count(key?: IDBValidKey | IDBKeyRange): IDBRequest;
9063+
count(key?: IDBValidKey | IDBKeyRange): IDBRequest<number>;
90649064
/**
90659065
* 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
90669066
* satisfied with the data already in store the upgrade
@@ -9075,7 +9075,7 @@ interface IDBObjectStore {
90759075
* If successful, request's result will
90769076
* be undefined.
90779077
*/
9078-
delete(key: IDBValidKey | IDBKeyRange): IDBRequest;
9078+
delete(key: IDBValidKey | IDBKeyRange): IDBRequest<undefined>;
90799079
/**
90809080
* Deletes the index in store with the given name.
90819081
* Throws an "InvalidStateError" DOMException if not called within an upgrade
@@ -9087,41 +9087,41 @@ interface IDBObjectStore {
90879087
* given key or key range in query.
90889088
* If successful, request's result will be the value, or undefined if there was no matching record.
90899089
*/
9090-
get(query: IDBValidKey | IDBKeyRange): IDBRequest;
9090+
get(query: IDBValidKey | IDBKeyRange): IDBRequest<any | undefined>;
90919091
/**
90929092
* Retrieves the values of the records matching the
90939093
* given key or key range in query (up to count if given).
90949094
* If successful, request's result will
90959095
* be an Array of the values.
90969096
*/
9097-
getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest;
9097+
getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest<any[]>;
90989098
/**
90999099
* Retrieves the keys of records matching the
91009100
* given key or key range in query (up to count if given).
91019101
* If successful, request's result will
91029102
* be an Array of the keys.
91039103
*/
9104-
getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest;
9104+
getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest<IDBValidKey[]>;
91059105
/**
91069106
* Retrieves the key of the first record matching the
91079107
* given key or key range in query.
91089108
* If successful, request's result will be the key, or undefined if there was no matching record.
91099109
*/
9110-
getKey(query: IDBValidKey | IDBKeyRange): IDBRequest;
9110+
getKey(query: IDBValidKey | IDBKeyRange): IDBRequest<IDBValidKey | undefined>;
91119111
index(name: string): IDBIndex;
91129112
/**
91139113
* Opens a cursor over the records matching query,
91149114
* ordered by direction. If query is null, all records in store are matched.
91159115
* If successful, request's result will be an IDBCursorWithValue pointing at the first matching record, or null if there were no matching records.
91169116
*/
9117-
openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest;
9117+
openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest<IDBCursorWithValue | null>;
91189118
/**
91199119
* 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.
91209120
* If successful, request's result will be an IDBCursor pointing at the first matching record, or
91219121
* null if there were no matching records.
91229122
*/
9123-
openKeyCursor(query?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest;
9124-
put(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest;
9123+
openKeyCursor(query?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest<IDBCursor | null>;
9124+
put(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest<any>;
91259125
}
91269126

91279127
declare var IDBObjectStore: {
@@ -9134,7 +9134,7 @@ interface IDBOpenDBRequestEventMap extends IDBRequestEventMap {
91349134
"upgradeneeded": IDBVersionChangeEvent;
91359135
}
91369136

9137-
interface IDBOpenDBRequest extends IDBRequest {
9137+
interface IDBOpenDBRequest extends IDBRequest<IDBDatabase> {
91389138
onblocked: ((this: IDBOpenDBRequest, ev: Event) => any) | null;
91399139
onupgradeneeded: ((this: IDBOpenDBRequest, ev: IDBVersionChangeEvent) => any) | null;
91409140
addEventListener<K extends keyof IDBOpenDBRequestEventMap>(type: K, listener: (this: IDBOpenDBRequest, ev: IDBOpenDBRequestEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
@@ -9153,14 +9153,14 @@ interface IDBRequestEventMap {
91539153
"success": Event;
91549154
}
91559155

9156-
interface IDBRequest extends EventTarget {
9156+
interface IDBRequest<T> extends EventTarget {
91579157
/**
91589158
* When a request is completed, returns the error (a DOMException), or null if the request succeeded. Throws
91599159
* a "InvalidStateError" DOMException if the request is still pending.
91609160
*/
91619161
readonly error: DOMException | null;
9162-
onerror: ((this: IDBRequest, ev: Event) => any) | null;
9163-
onsuccess: ((this: IDBRequest, ev: Event) => any) | null;
9162+
onerror: ((this: IDBRequest<T>, ev: Event) => any) | null;
9163+
onsuccess: ((this: IDBRequest<T>, ev: Event) => any) | null;
91649164
/**
91659165
* Returns "pending" until a request is complete,
91669166
* then returns "done".
@@ -9171,7 +9171,7 @@ interface IDBRequest extends EventTarget {
91719171
* or undefined if the request failed. Throws a
91729172
* "InvalidStateError" DOMException if the request is still pending.
91739173
*/
9174-
readonly result: any;
9174+
readonly result: T;
91759175
/**
91769176
* Returns the IDBObjectStore, IDBIndex, or IDBCursor the request was made against, or null if is was an open
91779177
* request.
@@ -9182,15 +9182,15 @@ interface IDBRequest extends EventTarget {
91829182
* If this as an open request, then it returns an upgrade transaction while it is running, or null otherwise.
91839183
*/
91849184
readonly transaction: IDBTransaction | null;
9185-
addEventListener<K extends keyof IDBRequestEventMap>(type: K, listener: (this: IDBRequest, ev: IDBRequestEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
9185+
addEventListener<K extends keyof IDBRequestEventMap>(type: K, listener: (this: IDBRequest<T>, ev: IDBRequestEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
91869186
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
9187-
removeEventListener<K extends keyof IDBRequestEventMap>(type: K, listener: (this: IDBRequest, ev: IDBRequestEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
9187+
removeEventListener<K extends keyof IDBRequestEventMap>(type: K, listener: (this: IDBRequest<T>, ev: IDBRequestEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
91889188
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
91899189
}
91909190

91919191
declare var IDBRequest: {
9192-
prototype: IDBRequest;
9193-
new(): IDBRequest;
9192+
prototype: IDBRequest<any>;
9193+
new(): IDBRequest<any>;
91949194
};
91959195

91969196
interface IDBTransactionEventMap {

0 commit comments

Comments
 (0)