GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix: more typedefs improvements by plbstl · Pull Request #366 · pillarjs/iconv-lite Conversation
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thanks! I tested commit 519fd3b locally using this reproduction repo: Here’s the matrix I tried:
With this PR applied, both
(I'm not sure how common this configuration is in practice.) In my local testing, commenting out the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@kyota-fujikura Thank you very much for the feedback. And you're right. Removing After cloning https://github.com/kyota-fujikura/iconv-lite-type-error-reproduction, I also added a import { encode, decode } from "iconv-lite"; const input = "こんにちは"; const encoding = "shift_jis"; const encoded = encode(input, encoding); const decoded = decode(encoded, encoding); console.log({ encoded, decoded }); and scritps for running the files directly with NodeJS: "check-default-import-ts": "node src/default-import.ts", "check-named-import-ts": "node src/named-import.ts", "check-namespace-import-ts": "node src/namespace-import.ts" They all worked as expected. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Pull Request Test Coverage Report for Build 20557192437Details
💛 - Coveralls |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
For me it's good to, when the pr ? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This pull request refactors the CommonJS export pattern in iconv-lite to improve TypeScript typedef compatibility. The changes align with the cjs-module-lexer compatibility patterns by switching from iconv.x = ... to exports.x = ... throughout the codebase, and updating the TypeScript definitions to use namespace-level exports with export = syntax.
iconv.property assignments with exports.property throughout lib/index.jslib/index.d.ts from a nested object interface to namespace-level exportsesModuleInterop: true to tsconfig.json for better ES module/CommonJS interoperabilityCopilot reviewed 1 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tsconfig.json | Added esModuleInterop: true compiler option for improved ES module compatibility |
| lib/index.js | Refactored all property assignments and method definitions from iconv.x pattern to exports.x pattern for proper CommonJS exports |
| lib/index.d.ts | Restructured type definitions from nested object structure to namespace-level exports matching the new JavaScript export style |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -102,7 +102,7 @@ iconv.getCodec = function getCodec (encoding) { | |||
| // | |||
| codec = new codecDef(codecOptions, iconv) | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The variable iconv is used here but should be exports to match the refactoring throughout the rest of the file. Line 7 defines var iconv = module.exports, but since all other references have been changed to use exports directly, this reference should also be updated to exports for consistency.
| codec = new codecDef(codecOptions, iconv) | |
| codec = new codecDef(codecOptions, exports) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
it should be module.exports or icons, imo
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| iconv.encodingExists = function encodingExists (enc) { | ||
| exports.encodingExists = function encodingExists (enc) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
there's something that doesn't add up, and it's that technically with iconv.[nameOfObject] that's already being done, I can't understand why it doesn't work for TypeScript with the old way, but it does work with this new way, I feel like it's just a bug in attw that can't detect that rule properly
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It has to do with how TypeScript transpiles the userland code.
Also, since exports. is the right way to export modules (for use in ESM), it is an okay thing to do.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
We want to verify how it behaves without that option, since it is disabled by default. Additionally, it’s not an option used in DefinitelyTyped for testing, so let’s leave it disabled.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I prefer using module.exports over exports, since that helps prevent cycles, but otherwise the JS changes look correct to me.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -102,7 +102,7 @@ iconv.getCodec = function getCodec (encoding) { | |||
| // | |||
| codec = new codecDef(codecOptions, iconv) | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
it should be module.exports or icons, imo
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I’ll leave it open for a bit longer so more people can take a look, and I’ll try to release it in January
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
TypeScript types broken in ES Modules
There was an error while loading. Please reload this page.