Closed FossPrime closed 2 years ago
Updated with a sandbox that highlights the problem.
Found another workaround
import { default as Datastore } from '@seald-io/nedb' // currently works
// wont work, Datastore is an Object with a Datastore property
// But our types restrict access to that
// import Datastore from '@seald-io/nedb'
I still hold that this PR is the best solution to the issue. It causes the index.js default to work as default under TS.
Alternative solution, that makes Nedb available to TS ESM users, but exposes a non existent Datastore property to all CJS users.
export default Nedb;
export { Nedb as Datastore }
@rayfoss I am sorry but I am not very clear on what the problem is.
I just tried a quick demo of using NeDB with TypeScript, and it seems to work fine with import Datastore from '@seald-io/nedb'
, with the current typings, as soon as I add the needed "esModuleInterop": true
in tsconfig, because the package is in CJS format.
I tried reading through your sandbox, but between ts-node, nodemon, http stuff, ..., i could not really understand what does not work.
EDIT: Also, it does not work with your change if I do not put the esModuleInterop
.
TypeStrong is kicking the can on ESM support... probably till 4.6 or 4.7, or maybe even 5 :(
The previous definition only worked because of an optional compatibility layer that makes CommonJS look like native ESM.
Workaround