Skip to content

Fix IDBIndex interface for openCursor/openKeyCursor #7218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
falsandtru opened this issue Feb 24, 2016 · 3 comments
Closed

Fix IDBIndex interface for openCursor/openKeyCursor #7218

falsandtru opened this issue Feb 24, 2016 · 3 comments
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this

Comments

@falsandtru
Copy link
Contributor

TypeScript Version:

master

Expected:

https://www.w3.org/TR/IndexedDB/

    openCursor(range?: any, direction?: string): IDBRequest;
    openKeyCursor(range?: any, direction?: string): IDBRequest;

Actual:

    openCursor(range?: IDBKeyRange, direction?: string): IDBRequest;
    openKeyCursor(range?: IDBKeyRange, direction?: string): IDBRequest;
@mhegazy mhegazy added Bug A bug in TypeScript Help Wanted You can do this Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Feb 24, 2016
@DanielRosenwasser
Copy link
Member

I don't think this is the appropriate change. From the spec:

If the range parameter is a key range then the cursor's range must be set to that range. Otherwise, if the range parameter is a valid key then the cursor's range is set to key range containing only that key value. If the range parameter is not specified, the cursor's key range is left as undefined.

Elsewhere:

A value is said to be a valid key if it is one of the following ECMAScript [ECMA-262] types: Number primitive value, String primitive value, Date object, or Array object. An Array is only a valid key if every item in the array is defined and is a valid key (i.e. sparse arrays can not be valid keys) and if the Array doesn't directly or indirectly contain itself.

So based on that (as well as #3496 (comment) and #3988 (comment)) it sounds like you want a

type IDBValidKey = number | string | Date | IDBArrayKey;
interface IDBArrayKey extends Array<IDBValidKey>{
}
    openCursor(range?: IDBKeyRange | IDBValidKey, direction?: string): IDBRequest;
    openKeyCursor(range?: IDBKeyRange | IDBValidKey, direction?: string): IDBRequest;

@falsandtru
Copy link
Contributor Author

It should be an additional(another) pr because IDBValidKey is not defined by WebIDL. At least, we needs to unify the declaration. IDBObjectStore interface has a same method, different signature.

interface IDBObjectStore {
    ...
    openCursor(range?: any, direction?: string): IDBRequest;
}

And range?: any is valid, range?: IDBKeyRange is invalid in the spec. So firstly, we should fix to range?: any.

@falsandtru
Copy link
Contributor Author

This issue is fixed.

@mhegazy mhegazy modified the milestones: TypeScript 2.0, Community Mar 17, 2016
@zhengbli zhengbli added Fixed A PR has been merged for this issue and removed Fixed in TSJS repo labels Apr 27, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

4 participants