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

Switch to CommonJS export in types #16

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

Conversation

karlhorky
Copy link

Thanks for @jsdevtools/rehype-toc!

To avoid having to access .default in moduleResolution: 'Node16' or newer:

TypeScript Playground

import rehypeTocModule from '@jsdevtools/rehype-toc';

const moduleExpected: (...args: any[]) => any = rehypeTocModule; // 💥

const moduleActual: { default: (...args: any[]) => any } = rehypeTocModule;

const defaultActual: (...args: any[]) => any = rehypeTocModule.default;

Error message:

'moduleExpected' is declared but its value is never read.(6133)
Type 'typeof import("file:///node_modules/@jsdevtools/rehype-toc/lib/index")' is not assignable to type '(...args: any[]) => any'.
  Type 'typeof import("file:///node_modules/@jsdevtools/rehype-toc/lib/index")' provides no match for the signature '(...args: any[]): any'.(2322)

Interestingly I don't see a problem on Are the types wrong?:

Screenshot 2024-07-29 at 19 11 08

cc @andrewbranch

Copy link

@andrewbranch andrewbranch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t think this change is valid. You can’t have an export * and an export =.

@karlhorky
Copy link
Author

karlhorky commented Jul 29, 2024

Ah alright, thanks for the response!

Maybe this would require a more complex type, since after reviewing the lib/index.js it appears that both rehypeTocModule.default and rehypeTocModule actually exist:

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
    for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.toc = void 0;
const rehype_toc_1 = require("./rehype-toc");
Object.defineProperty(exports, "toc", { enumerable: true, get: function () { return rehype_toc_1.toc; } });
__exportStar(require("./types"), exports);
// Export `toc` as the default export
exports.default = rehype_toc_1.toc;
// CommonJS default export hack
/* eslint-env commonjs */
if (typeof module === "object" && typeof module.exports === "object") {
    module.exports = Object.assign(module.exports.default, module.exports);
}
//# sourceMappingURL=index.js.map

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.

2 participants