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

Fix type definition #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

jdforsythe
Copy link

The current type definition requires esModuleInterop: true to work. Otherwise you get errors like: TypeError: (0 , keypair_1.default) is not a function

References:

This change uses Declaration Merging and the export = syntax so it works with and without esModuleInterop.

import * as keypair from 'keypair';

const keys: keypair.KeypairResults = keypair();

The current type definition requires `esModuleInterop: true` to work. Otherwise you get errors like: `TypeError: (0 , keypair_1.default) is not a function`

References:

- https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-d-ts.html - "Note that using export default in your .d.ts files requires esModuleInterop: true to work. If you can’t have esModuleInterop: true in your project, such as when you’re submitting a PR to Definitely Typed, you’ll have to use the export= syntax instead. This older syntax is harder to use but works everywhere."
- https://stackoverflow.com/questions/55910285/export-custom-type-definition-with-module-exports
- https://www.typescriptlang.org/docs/handbook/declaration-files/templates/module-function-d-ts.html

This change uses Declaration Merging and the `export =` syntax so it works with and without `esModuleInterop`.

```ts
import * as keypair from 'keypair';

const keys: keypair.KeypairResults = keypair();
```
@snowy008

This comment was marked as off-topic.

@juliangruber
Copy link
Owner

juliangruber commented Oct 28, 2022

Could someone with more typescript experience than me please review this?

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.

3 participants