dumbmatter / fakeIndexedDB

A pure JS in-memory implementation of the IndexedDB API
Apache License 2.0
562 stars 69 forks source link

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

Closed clintharris closed 3 years ago

clintharris commented 3 years ago

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

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Closing, per discussion in #23.