Skip to content

Commit bbf761b

Browse files
authored
Merge pull request #530 from LinusU/idbrequest
Type the result property on IDBRequest
2 parents 68fe8bb + e29b2ec commit bbf761b

9 files changed

+160
-92
lines changed

baselines/dom.generated.d.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8312,13 +8312,13 @@ interface IDBCursor {
83128312
* Delete the record pointed at by the cursor with a new value.
83138313
* If successful, request's result will be undefined.
83148314
*/
8315-
delete(): IDBRequest;
8315+
delete(): IDBRequest<undefined>;
83168316
/**
83178317
* Updated the record pointed at by the cursor with a new value.
83188318
* Throws a "DataError" DOMException if the effective object store uses in-line keys and the key would have changed.
83198319
* If successful, request's result will be the record's key.
83208320
*/
8321-
update(value: any): IDBRequest;
8321+
update(value: any): IDBRequest<IDBValidKey>;
83228322
}
83238323

83248324
declare var IDBCursor: {
@@ -8444,40 +8444,40 @@ interface IDBIndex {
84448444
* If successful, request's result will be the
84458445
* count.
84468446
*/
8447-
count(key?: IDBValidKey | IDBKeyRange): IDBRequest;
8447+
count(key?: IDBValidKey | IDBKeyRange): IDBRequest<number>;
84488448
/**
84498449
* Retrieves the value of the first record matching the
84508450
* given key or key range in query.
84518451
* If successful, request's result will be the value, or undefined if there was no matching record.
84528452
*/
8453-
get(key: IDBValidKey | IDBKeyRange): IDBRequest;
8453+
get(key: IDBValidKey | IDBKeyRange): IDBRequest<any | undefined>;
84548454
/**
84558455
* Retrieves the values of the records matching the given key or key range in query (up to count if given).
84568456
* If successful, request's result will be an Array of the values.
84578457
*/
8458-
getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest;
8458+
getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest<any[]>;
84598459
/**
84608460
* Retrieves the keys of records matching the given key or key range in query (up to count if given).
84618461
* If successful, request's result will be an Array of the keys.
84628462
*/
8463-
getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest;
8463+
getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest<IDBValidKey[]>;
84648464
/**
84658465
* Retrieves the key of the first record matching the
84668466
* given key or key range in query.
84678467
* If successful, request's result will be the key, or undefined if there was no matching record.
84688468
*/
8469-
getKey(key: IDBValidKey | IDBKeyRange): IDBRequest;
8469+
getKey(key: IDBValidKey | IDBKeyRange): IDBRequest<IDBValidKey | undefined>;
84708470
/**
84718471
* Opens a cursor over the records matching query,
84728472
* ordered by direction. If query is null, all records in index are matched.
84738473
* If successful, request's result will be an IDBCursorWithValue, or null if there were no matching records.
84748474
*/
8475-
openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest;
8475+
openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest<IDBCursorWithValue | null>;
84768476
/**
84778477
* 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.
84788478
* If successful, request's result will be an IDBCursor, or null if there were no matching records.
84798479
*/
8480-
openKeyCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest;
8480+
openKeyCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest<IDBCursor | null>;
84818481
}
84828482

84838483
declare var IDBIndex: {
@@ -8556,19 +8556,19 @@ interface IDBObjectStore {
85568556
* Returns the associated transaction.
85578557
*/
85588558
readonly transaction: IDBTransaction;
8559-
add(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest;
8559+
add(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest<IDBValidKey>;
85608560
/**
85618561
* Deletes all records in store.
85628562
* If successful, request's result will
85638563
* be undefined.
85648564
*/
8565-
clear(): IDBRequest;
8565+
clear(): IDBRequest<undefined>;
85668566
/**
85678567
* Retrieves the number of records matching the
85688568
* given key or key range in query.
85698569
* If successful, request's result will be the count.
85708570
*/
8571-
count(key?: IDBValidKey | IDBKeyRange): IDBRequest;
8571+
count(key?: IDBValidKey | IDBKeyRange): IDBRequest<number>;
85728572
/**
85738573
* 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
85748574
* satisfied with the data already in store the upgrade
@@ -8583,7 +8583,7 @@ interface IDBObjectStore {
85838583
* If successful, request's result will
85848584
* be undefined.
85858585
*/
8586-
delete(key: IDBValidKey | IDBKeyRange): IDBRequest;
8586+
delete(key: IDBValidKey | IDBKeyRange): IDBRequest<undefined>;
85878587
/**
85888588
* Deletes the index in store with the given name.
85898589
* Throws an "InvalidStateError" DOMException if not called within an upgrade
@@ -8595,41 +8595,41 @@ interface IDBObjectStore {
85958595
* given key or key range in query.
85968596
* If successful, request's result will be the value, or undefined if there was no matching record.
85978597
*/
8598-
get(query: IDBValidKey | IDBKeyRange): IDBRequest;
8598+
get(query: IDBValidKey | IDBKeyRange): IDBRequest<any | undefined>;
85998599
/**
86008600
* Retrieves the values of the records matching the
86018601
* given key or key range in query (up to count if given).
86028602
* If successful, request's result will
86038603
* be an Array of the values.
86048604
*/
8605-
getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest;
8605+
getAll(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest<any[]>;
86068606
/**
86078607
* Retrieves the keys of records matching the
86088608
* given key or key range in query (up to count if given).
86098609
* If successful, request's result will
86108610
* be an Array of the keys.
86118611
*/
8612-
getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest;
8612+
getAllKeys(query?: IDBValidKey | IDBKeyRange, count?: number): IDBRequest<IDBValidKey[]>;
86138613
/**
86148614
* Retrieves the key of the first record matching the
86158615
* given key or key range in query.
86168616
* If successful, request's result will be the key, or undefined if there was no matching record.
86178617
*/
8618-
getKey(query: IDBValidKey | IDBKeyRange): IDBRequest;
8618+
getKey(query: IDBValidKey | IDBKeyRange): IDBRequest<IDBValidKey | undefined>;
86198619
index(name: string): IDBIndex;
86208620
/**
86218621
* Opens a cursor over the records matching query,
86228622
* ordered by direction. If query is null, all records in store are matched.
86238623
* If successful, request's result will be an IDBCursorWithValue pointing at the first matching record, or null if there were no matching records.
86248624
*/
8625-
openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest;
8625+
openCursor(range?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest<IDBCursorWithValue | null>;
86268626
/**
86278627
* 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.
86288628
* If successful, request's result will be an IDBCursor pointing at the first matching record, or
86298629
* null if there were no matching records.
86308630
*/
8631-
openKeyCursor(query?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest;
8632-
put(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest;
8631+
openKeyCursor(query?: IDBValidKey | IDBKeyRange, direction?: IDBCursorDirection): IDBRequest<IDBCursor | null>;
8632+
put(value: any, key?: IDBValidKey | IDBKeyRange): IDBRequest<IDBValidKey>;
86338633
}
86348634

86358635
declare var IDBObjectStore: {
@@ -8642,7 +8642,7 @@ interface IDBOpenDBRequestEventMap extends IDBRequestEventMap {
86428642
"upgradeneeded": IDBVersionChangeEvent;
86438643
}
86448644

8645-
interface IDBOpenDBRequest extends IDBRequest {
8645+
interface IDBOpenDBRequest extends IDBRequest<IDBDatabase> {
86468646
onblocked: ((this: IDBOpenDBRequest, ev: Event) => any) | null;
86478647
onupgradeneeded: ((this: IDBOpenDBRequest, ev: IDBVersionChangeEvent) => any) | null;
86488648
addEventListener<K extends keyof IDBOpenDBRequestEventMap>(type: K, listener: (this: IDBOpenDBRequest, ev: IDBOpenDBRequestEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
@@ -8661,14 +8661,14 @@ interface IDBRequestEventMap {
86618661
"success": Event;
86628662
}
86638663

8664-
interface IDBRequest extends EventTarget {
8664+
interface IDBRequest<T = any> extends EventTarget {
86658665
/**
86668666
* When a request is completed, returns the error (a DOMException), or null if the request succeeded. Throws
86678667
* a "InvalidStateError" DOMException if the request is still pending.
86688668
*/
86698669
readonly error: DOMException | null;
8670-
onerror: ((this: IDBRequest, ev: Event) => any) | null;
8671-
onsuccess: ((this: IDBRequest, ev: Event) => any) | null;
8670+
onerror: ((this: IDBRequest<T>, ev: Event) => any) | null;
8671+
onsuccess: ((this: IDBRequest<T>, ev: Event) => any) | null;
86728672
/**
86738673
* Returns "pending" until a request is complete,
86748674
* then returns "done".
@@ -8679,7 +8679,7 @@ interface IDBRequest extends EventTarget {
86798679
* or undefined if the request failed. Throws a
86808680
* "InvalidStateError" DOMException if the request is still pending.
86818681
*/
8682-
readonly result: any;
8682+
readonly result: T;
86838683
/**
86848684
* Returns the IDBObjectStore, IDBIndex, or IDBCursor the request was made against, or null if is was an open
86858685
* request.
@@ -8690,9 +8690,9 @@ interface IDBRequest extends EventTarget {
86908690
* If this as an open request, then it returns an upgrade transaction while it is running, or null otherwise.
86918691
*/
86928692
readonly transaction: IDBTransaction | null;
8693-
addEventListener<K extends keyof IDBRequestEventMap>(type: K, listener: (this: IDBRequest, ev: IDBRequestEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
8693+
addEventListener<K extends keyof IDBRequestEventMap>(type: K, listener: (this: IDBRequest<T>, ev: IDBRequestEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
86948694
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
8695-
removeEventListener<K extends keyof IDBRequestEventMap>(type: K, listener: (this: IDBRequest, ev: IDBRequestEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
8695+
removeEventListener<K extends keyof IDBRequestEventMap>(type: K, listener: (this: IDBRequest<T>, ev: IDBRequestEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
86968696
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
86978697
}
86988698

@@ -17043,4 +17043,4 @@ type VRDisplayEventReason = "mounted" | "navigation" | "requested" | "unmounted"
1704317043
type VideoFacingModeEnum = "user" | "environment" | "left" | "right";
1704417044
type VisibilityState = "hidden" | "visible" | "prerender";
1704517045
type WorkerType = "classic" | "module";
17046-
type XMLHttpRequestResponseType = "" | "arraybuffer" | "blob" | "document" | "json" | "text";
17046+
type XMLHttpRequestResponseType = "" | "arraybuffer" | "blob" | "document" | "json" | "text";

0 commit comments

Comments
 (0)