-
Notifications
You must be signed in to change notification settings - Fork 293
types: improve type definitions and add missing APIs #330
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: improve type definitions and add missing APIs #330
Conversation
Also renamed `scripts/template-index.d.ts` to `lib/index-template.d.ts`
Pull Request Test Coverage Report for Build 17037641521Details
💛 - Coveralls |
…reamingAPI`, `getCodec`, `_canonicalizeEncoding`, `encodings`, `_codecDataCache`, `defaultCharUnicode`, `defaultCharSingleByte` to the public API
…fs/improve-typings
Signed-off-by: Sebastian Beltran <[email protected]>
|
Hey, I just modified your PR to add tests for the types. I’m still testing a few things to make sure I don’t break anything, but feel free to push changes if you see something missing. |
Signed-off-by: Sebastian Beltran <[email protected]>
Signed-off-by: Sebastian Beltran <[email protected]>
|
Very valid. I've pushed the relevant changes. |
Signed-off-by: Sebastian Beltran <[email protected]>
bjohansebas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: Sebastian Beltran <[email protected]>
Signed-off-by: Sebastian Beltran <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR significantly improves TypeScript support for iconv-lite by adding comprehensive type definitions, separating encode/decode options, and introducing an auto-generation script for encoding types. The changes enhance developer experience with better type safety and IntelliSense support.
Key changes:
- Added exhaustive union type of 400+ supported encodings with auto-generation script
- Split
Optionsinto separateDecodeOptionsandEncodeOptionsinterfaces for better type specificity - Enhanced API type definitions with detailed JSDoc comments and proper type guards
Reviewed changes
Copilot reviewed 9 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| types/encodings.d.ts | Auto-generated exhaustive union type of all 400+ supported encoding strings |
| lib/index.d.ts | Complete rewrite of type definitions with separated encode/decode options, improved documentation, and better type safety |
| generation/gen-typings.js | New script to auto-generate encoding types from source encoding files |
| test/types/import.ts | Test file to verify all exported types can be imported |
| test/types/iconv.ts | Comprehensive type tests using expect-type library |
| package.json | Added TypeScript tooling dependencies and test scripts |
| tsconfig.json | New TypeScript configuration for type checking |
| .npmignore | Exclude tsconfig.json from npm package |
| eslint.config.js | Enable TypeScript support in ESLint |
| Changelog.md | Document the improvements |
| .github/workflows/ci.yml | Add TypeScript test job and exclude Windows+Node 17 combination |
| .github/workflows/iojs.yml | Remove TypeScript dev dependencies for older Node versions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hey @bjohansebas, can you port this to the v1 branch? |
|
Hi, |
|
I've been experimenting. I initially did not want to modify It's a straightforward change. Rather than setting properties/methods in the -- iconv.encodings = null
-- iconv.encode = function encode (str, encoding, options) {...}
++ exports.encodings = null
++ exports.encode = function encode (str, encoding, options) {...}
Line 103 in d85f5ab
I have a working branch (https://github.com/plbstl/iconv-lite/tree/more-typedefs-improvements) with the |
@prigaux Can you provide more information? How are you attempting to access |
|
Hey @prigaux , could you please create a new issue with a minimal reproducible example? |
|
(sorry for not giving enough information, i thought i was enough to reproduce) To reproduce, you need Reproduced with
=> |
|
@prigaux I can’t manage to reproduce it. Could you create a clean GitHub repo with that so we can debug it more easily? |
|
Hi, @plbstl @bjohansebas
I faced with the same error message; I'm not sure if I'm with same condition though. Lines 128 to 129 in d85f5ab
I guess this is because iconv instance is now exported as default property, you need to import using default import instead of namespace import. |
|
Here is a clean repo: https://github.com/prigaux/iconv-lite-typescript-modules-issue I have nodejs 24.11.1-1nodesource1 |
Improved type definitions when using this library.
npm run typegenOptionstoDecodeOptionsandEncodeOptionscloses #299