-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Publish Typescript declaration file #23
Comments
Thanks for the suggestion! Is it actually that simple? I remember being very confused by how TypeScript modules work, and that is both why the |
even if it just exported the typescript interfaces |
I'd accept a PR that exports all the classes as named exports, and |
Does the typescript declaration exist? |
Hello, I just createad a PR which adds declaration files to the build folder so it shouldn't affect backwards compatibility. |
Hi, I'd also like to offer PR #58 as a possible solution. It differs a bit from Ricardo's PR in that it writes
This seems to work fine in Typescript, for example: import FDBFactory from 'fake-indexeddb/lib/FDBFactory'
const factory = new FDBFactory() I published my fork with these changes if anyone wants to kick the tires:
|
Question for @clintharris and @Richifg (and anyone else who wants to chime in)... Does it actually make sense to export types like this? Or should we have manually-written .d.ts file that just says "fake-indexeddb behaves just like the normal IndexedDB types included with TypeScript"? Because in the case where they differ for some reason, why would anyone prefer the fake-indexeddb version? Since your application code is presumably written using the built-in TypeScript types. Or should fake-indexeddb itself be modified to explicitly implement the interfaces from the built-in TypeScript types? I feel like that might be the real solution, and the least likely to cause problems down the road. Basically my concern is releasing this and breaking a bunch of people's builds due to some mundane type difference... |
I agree that it seems like having fake-indexedDB export objects that are typed using the standard, Typescript-provided IndexedDB types is the best long-term solution. With, maybe, occasional exceptions were it to offer custom API feature for doing non-standard things (e.g., a convenience function for resetting the entire state of fiDB, or getting access to the real IndexedDB globals, etc.). 🙂 And you have a good point about something like PRs #57 and #58 basically introducing "custom" types that could cause problems in the future--not necessarily if they were released tomorrow, but in a following release if the project were to then start exporting standard API types. In other words, if the project started exporting |
Okay, so after all: how do I solve this issue that TypeScript gives me an error that it has no declaration file for it? |
|
Just wondering could we mitigate some of the issues if we were to export types as an OR between the This way users could use any common APIs easily but anything like EDIT: This is how I imagine it typescript playground link thats very long |
@Dahaden thanks for the suggestion and the prototype code! The problem I worry about with this is if you're passing around IndexedDB variables in your application code, that code shouldn't have to care that fake-indexeddb exists, so any difference in types between fake-indexeddb and IndexedDB could result in a lot of false positive TypeScript errors. Extension of your example. Ultimately I think there's not much to gain by doing anything other than using the built-in TypeScript IndexedDB types. Anything in fake-indexeddb that's not in real IndexedDB is not part of the public API currently anyway. (For your example, IDBTransaction.commit actually does exist.) If eventually stuff is added to the public API like #50 or #51, then the fake-indexeddb types could just be like I'm going to try to do a new release containing TypeScript types and maybe also moving to ES modules if that doesn't cause too many issues. Working on that now in the v4 branch: https://github.com/dumbmatter/fakeIndexedDB/tree/v4 |
I published a beta if anyone wants to try it, seems to work fine for me. https://www.npmjs.com/package/fake-indexeddb/v/4.0.0-beta.1 |
If it helps anyone, I'm currently working around this by just wrapping import FDBFactory from 'fake-indexeddb'
export const getDatabase = () =>
new FDBFactory() as typeof indexedDB |
Finally fixed in v4.0.0 https://github.com/dumbmatter/fakeIndexedDB/releases/tag/v4.0.0 |
Hi @dumbmatter.
Thanks for such an awesome module! I'm currently using this for some tests in a library of mine that I'm transitioning from JavaScript to Typescript. I was wondering if it would be possible to push a new release out with some Typescript declaration files. It shouldn't be too hard to do since you're using Typescript yourself. Just setting
declaration: true
and removingallowJs: true
intsconfig.json
should do the trick.The text was updated successfully, but these errors were encountered: