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

Add ability to generate type declaration files as part of build #58

Closed
wants to merge 1 commit into from

Conversation

clintharris
Copy link

Summary

This PR modifies the build script to include generating ambient type declaration files. The files are generated in the "legacy API" lib/ folder so that the existing paths used to reference the CommonJS modules will continue to work with the Typescript compiler. For example, the Typescript compiler will not complain about the following:

import FDBFactory from 'fake-indexeddb/lib/FDBFactory'; // 👍 Resolves to lib/FDBFactory.js, and tsc is also happy because it sees lib/FDBFactory.d.ts
indexedDB = new FDBFactory();

Changes

  • Adds a new build-typedefs npm script. This writes .d.ts files to the lib/ directory.
  • Modifies the build npm script to to run build-typedefs.
  • Modifies .gitignore so that the type declaration files (lib/*.d.ts) are ignored.

Example

$ yarn build-typedefs

Result:

 |-package.json
 |-lib
 | |-FDBDatabase.js
 | |-FDBDatabase.d.ts ✨
 | |-FDBIndex.js
 | |-FDBIndex.d.ts ✨
...

How to try it out

I published a version with these changes to make it easier to test:

npm install -D @clintharris/fake-indexeddb

@dumbmatter
Copy link
Owner

Thanks! This is cool. This is just for the "lib" imports right, not the main import? Is it intended that I'd also merge #57?

@clintharris
Copy link
Author

Right, I was thinking it would just cover the stuff in lib and not the main import. It's an alternative to #57 (which wasn't working for me when I tried to import stuff from lib). But I think, given the discussion in #23, this PR is not the best solution.

@clintharris
Copy link
Author

Closing, per discussion in #23.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants