Fix module export in type definitions #106
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TL;DR: From microsoft/TypeScript#7185 (comment):
Therefore the correct way to export the module in its type definitions would be using
export =
, and importing it should be done usingimport mockingoose = require('mockingoose')
.The module is exported using
module.exports =
, and the current type definitions export the module usingexport default
:mockingoose/src/index.js
Line 382 in 8090c8f
mockingoose/types.d.ts
Line 62 in 8090c8f
This prevents TS users using
allowSyntheticDefaultImports: true
from being able to import the package correctly:The following does pass TypeScript's compiler but fails at runtime:
Even after the proposed change, a regular import won't work at runtime:
Finally, the following does work after the proposed change, as expected as it is a CommonJS module:
Until the issue is fixed, as in the proposed change, TS users using
allowSyntheticDefaultImports: true
are forced to useconst mockingoose = require('mockingoose')
which loses all typings.