FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Switch to CommonJS export in types by karlhorky · Pull Request #16 · JS-DevTools/rehype-toc · GitHub

Repository navigation

Switch to CommonJS export in types - #16

Open
karlhorky wants to merge 1 commit into
JS-DevTools:masterfrom
karlhorky:patch-1
Open

karlhorky wants to merge 1 commit into
JS-DevTools:masterfrom
karlhorky:patch-1

Conversation

Copy link
Copy Markdown

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?:

cc @andrewbranch

andrewbranch left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

karlhorky commented Jul 29, 2024 •
edited
Loading

Copy link
Copy Markdown
Author

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

This branch has not been deployed

No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL