Skip to content
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

Definition of interface IDBDatabase, property objectStoreNames is wrong #3355

Open
lll000111 opened this issue Feb 8, 2017 · 2 comments
Open
Labels
incompleteness Something is missing Library definitions Issues or pull requests about core library definitions

Comments

@lll000111
Copy link
Contributor

lll000111 commented Feb 8, 2017

The property objectStoreNames of IndexedDB databases is a DOMStringList, not a string array as is set in Flow's type file https://github.com/facebook/flow/blob/v0.41.0/lib/indexeddb.js#L40

I don't know why the MDN page says "obsolete, don't use" about that type - there is no way around it, that is the type of that property. I got bit by Google Chrome (latest stable release) because I tried to use array method includes, but I have to use DOMStringList method contains.

@lll000111
Copy link
Contributor Author

lll000111 commented Feb 9, 2017

So it seems that DOMStringList is missing altogether.

Also, the definition of interface IDBRequest's property result is wrong, because right now it is set to IDBRequest. While the MDN page says that too it is wrong, Microsoft's documentation is correct and Mozilla's is wrong. The result can be anything depending on the type of request! For example, when I objectStore.get(...) something from the database result is the returned value.

The whole API with its many events on different levels really is messy, and the MDN documentation is really bad in this case. For example, they never explore what's on those event objects, never even use them in their examples, so no wonder they got it wrong.

I use this definition for DOMStringList:

declare interface DOMStringList {
    length: number;
    item: (number) => string | null;
    contains: (string) => boolean;
}

I use string as type, as far as I can see that is the same as DOMString (but the collection is no array).

Links:

FYI, TypeScript had the same issue: microsoft/TypeScript#12069

@lll000111
Copy link
Contributor Author

lll000111 commented Apr 22, 2017

The workaround referenced in the link to the private repo is to add this definition to my own .flowDecls/indexeddb.js:

declare interface DOMStringList {
     length: number;
     item: (number) => string | null;
     contains: (string) => boolean;
 }

and further down replace string[]:

    objectStoreNames: DOMStringList;

I didn't make this into a pull request because I'm not sure if this is an "interface" (what I use) or a "class" definition? That definition should then go into lib/dom.js. Interface seems right, but I also don't know where I should place it in that huge file.

This is how TypeScript defines it:

@nmn nmn added incompleteness Something is missing Library definitions Issues or pull requests about core library definitions labels Apr 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
incompleteness Something is missing Library definitions Issues or pull requests about core library definitions
Projects
None yet
Development

No branches or pull requests

2 participants