-
Notifications
You must be signed in to change notification settings - Fork 73
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
Types invalid with "type": "module"
and "moduleResolution": "Node16"
#118
Comments
Thanks for providing a repo with the repro! I looked at this and can't figure why this doesn't work. The way we type the fact the declare function anchor(md: MarkdownIt, opts?: anchor.AnchorOptions): void;
declare namespace anchor {
// [...]
export const permalink: {
headerLink: (opts?: HeaderLinkPermalinkOptions) => PermalinkGenerator
linkAfterHeader: (opts?: LinkAfterHeaderPermalinkOptions) => PermalinkGenerator
linkInsideHeader: (opts?: LinkInsideHeaderPermalinkOptions) => PermalinkGenerator
ariaHidden: (opts?: AriaHiddenPermalinkOptions) => PermalinkGenerator
};
}
export default anchor; And this is exactly how TypeScript compiles a TS file containing I'm clueless how to fix that, any suggestions welcome! 🙏 |
OK, setting I tried configuring the "main": "dist/markdownItAnchor.js",
"module": "dist/markdownItAnchor.mjs",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./types/index.d.ts",
"default": "dist/markdownItAnchor.mjs"
},
"require": {
"types": "./types/index.d.ts",
"default": "dist/markdownItAnchor.js"
}
}
},
"types": "./types/index.d.ts", Even putting the CJS and ESM outputs in different directories, e.g. Putting the |
Interesting: microsoft/TypeScript#49271 (comment) So you can fix it by using: import { default as anchorPlugin } from 'markdown-it-anchor' Still I believe TypeScript shouldn't require the dependency to have Edit: reported it here microsoft/TypeScript#50083 but was closed as wontfix |
Uh, that's an interesting limitation 🤔 (Apologize that I didn't have enough time to search for related issues yesterday, so I only posted a repro) Some ideas (might not be 100% correct though):
Anyway, as it's a known limitation (or work as intended) of typescript, I think libraries should try to follow it (at least for now). |
Facing the same issue trying to provide a hybrid library. I think it can be solved by placing a |
OH this seems to work well for both CJS and ESM imports, nice find @wickning1! 🙌 I just released version 8.6.5 with this fix, @meteorlxy let me know if that fixes the issue for you 😄 |
I'll consider this one fixed, feel free to reopen if I missed anything! |
Description
Current
types/index.d.ts
does not work well when:"type": "module"
inpackage.json
."moduleResolution": "Node16"
intsconfig.json
'scompilerOptions
.Reproduction
https://github.com/meteorlxy/markdown-it-anchor-types
The text was updated successfully, but these errors were encountered: