danestves / danestves/markdown-to-text

Module imports are problematic in TypeScript

Open
#19 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
28
Forks
9
PR merge metrics
No merged PRs in 30d

Description

I think it's deeply hidden inside: https://www.typescriptlang.org/tsconfig/#esModuleInterop

When you use:

```
import removeMarkdown from 'markdown-to-text';
```

The value `removeMarkdown` is actually `{ default: [Function: removeMarkdown] }` (not matching the types), It's not easy to work around this, because `import { default as....` also doesn't work, oddly *still* getting the value `{ default: [Function: removeMarkdown] }`. I'm using TypeScript 5.0.0.

I'm way out of my depth here, because I though since both my package and yours are both using `esModuleInterop: true` we'd be home free, but then I did read: https://github.com/microsoft/TypeScript/issues/27293#issuecomment-424053405, which kind of suggests that targeting CJS might be the issue, maybe.

In any event, a huge win might simply be to also export as a named `removeMarkdown`, so:

```
import { removeMarkdown } from 'markdown-to-text';
```

also works. This is not at all uncommon.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the TypeScript import behavior described for the markdown-to-text package and inspect how its current default export is exposed. The work is done when a named `removeMarkdown` import works as proposed and the existing default import behavior is understood or covered by an appropriate check.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.