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

Add Typescript for type checking (but still with js files) #81

Merged
merged 9 commits into from
May 4, 2024

Conversation

erikyo
Copy link
Collaborator

@erikyo erikyo commented Apr 5, 2024

This PR introduces TypeScript support and adds types within the npm package, addressing the suggestion raised in issue #80.

Changes include setting up the TypeScript environment, restructuring files for better organization, and adding strict types for module functions.

These enhancements aim to improve the module's compatibility with modern development practices and facilitate easier contributions from the community.


😇 Sorry for the 19 modified files but I really tried to keep it as small as possible!

close #80

add comments to types and types to package.json
@smhg
Copy link
Owner

smhg commented Apr 9, 2024

@erikyo Thank you for your work!

I'm so unfamilliar with TypeScript I didn't even realize it requires a build step. That's a bummer.
It seems the impact on the code base isn't too big though. Although I'd prefer the non-TypeScript changes be submitted in a separate PR/commit (renaming /lib to /src, typo's, package.json improvements,...). It would result in a very concise TypeScript-only PR.

However, before moving ahead with TypeScript, I'd very much appreciate @andris9 's feedback. He is the original author of this library and I'd like to know which approach he'd take.

@erikyo
Copy link
Collaborator Author

erikyo commented Apr 9, 2024

@andris9 the guy of node mailer? very gladly!

About the requested changes give me the time and I'll see if I can do what you asked for... unfortunately some are strictly necessary to compile without errors or pass the tests, but I'll see what I can do

@andris9
Copy link
Collaborator

andris9 commented Apr 9, 2024

As I haven't been active with this project for years, I don't consider myself to have any special rights to decide anything about the project's future. I think such decisions must be made by active maintainers only.

@erikyo
Copy link
Collaborator Author

erikyo commented Apr 9, 2024

Certainly, your comment, advice, or review is highly appreciated, as your expertise in the repository is invaluable. I acknowledge that the modification I propose may not be minor, but given the recent upgrade of the module to ES modules and the ongoing efforts to maintain its activity, I believe that this change, albeit potentially controversial, is worth submitting.

To be honest, the adjustment I suggest isn't excessively radical and ensures robust type checking.

in short, Is a matter of decision-making, so it would not be ideal to leave all the burden to @smhg

@erikyo
Copy link
Collaborator Author

erikyo commented Apr 9, 2024

I didn't even realize it requires a build step. That's a bummer.

For the time being yes, but simultaneously, it's the approach that ensures secure typing. It's a worthwhile endeavor. If you're interested, I can incorporate other automations to streamline the process. For instance, I could implement a prepublish script that handles tasks like clearing the lib folder, automatically building, and running tests.

It's essential to note that the compiled lib folder should no longer be published to github but only to npm (and, on other hands, the src folder isn't published on npm), check here

@smhg
Copy link
Owner

smhg commented Apr 10, 2024

@erikyo yes, having a prepublish script is definitely a good idea.

But, let's split up this PR if ok for you. I will add some comments in the code to clarify what I'm thinking about.

My current thinking: since I will be maintaining this library for the forseable future, I want to have the option to throw out types if I can't maintain them. It looks good currently, but I don't want to end up in a situation where I can't publish a bugfix because things don't run/build because of TS. Obviously I would rather first want to request your help when necessary to avoid this scenario.

package.json Outdated Show resolved Hide resolved
test/mo-compiler-test.js Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
src/mocompiler.js Outdated Show resolved Hide resolved
@erikyo
Copy link
Collaborator Author

erikyo commented Apr 10, 2024

let's split up this PR if ok for you

👍, and indeed sorry, I saw the review and indeed some edits were not required at all

I want to have the option to throw out types if I can't maintain them

at the current implementation types are only checked and generated using the typescript engine but the code isn't changed. i know that is a widely used repo, I will use white gloves

Obviously I would rather first want to request your help when necessary to avoid this scenario.

Obviously i'm here if you need!

src/poparser.js Outdated Show resolved Hide resolved
src/poparser.js Outdated Show resolved Hide resolved
src/mocompiler.js Outdated Show resolved Hide resolved
src/shared.js Outdated Show resolved Hide resolved
@erikyo erikyo force-pushed the #80/strictly-typed branch 7 times, most recently from c0d9561 to 143f973 Compare April 10, 2024 15:29
@erikyo erikyo requested a review from smhg April 10, 2024 15:31
@erikyo
Copy link
Collaborator Author

erikyo commented Apr 10, 2024

I have updated as you asked but I have a couple of concerns, that we may want to wipe out in the next PR:

  • The first is about the consolidation of all files into a single root folder, avoiding the placement of index.js directly in the repository root. Given that we can direct the 'bin' script to ./lib/index.js, there should be no issue with this approach. This consolidation aids in the import of definitions, as I've encountered difficulty setting up types because compiled definitions must be emitted into a separate folder from the sources. For this purpose, the @types/ folder is utilized, and the compiled files need to reference the index file in the root, similar to the files in 'lib'. Having everything centralized in one location would elegantly resolve these challenges.

  • jsdoc can be enhanced... definitions aren't wrong but typescript can provide a better type checking leveraging on that, you can give a try with tsc --checkjs and you will get some thing like this 👇. Sincerely, I wrote to you because i had to deal with this repo and the definitions were not clear to me and it took me longer than necessary to use it. I wish this would not happen to others, and typescript is a real friend of developers in this case ;)

lib/mocompiler.js(37,16): error TS2538: Type 'undefined' cannot be used as an index type.
lib/mocompiler.js(40,7): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
No index signature with a parameter of type 'string' was found on type '{}'.
lib/mocompiler.js(50,57): error TS7006: Parameter 'item' implicitly has an 'any' type.
lib/mocompiler.js(53,9): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
No index signature with a parameter of type 'string' was found on type '{}'.
lib/mocompiler.js(60,7): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
No index signature with a parameter of type 'string' was found on type '{}'.
lib/mocompiler.js(102,13): error TS2314: Generic type 'Array<T>' requires 1 type argument(s).
lib/mocompiler.js(152,19): error TS2307: Cannot find module './index.d.ts' or its corresponding type declarations.
lib/mocompiler.js(160,16): error TS7006: Parameter 'translation' implicitly has an 'any' type.
lib/mocompiler.js(187,19): error TS2307: Cannot find module './index.d.ts' or its corresponding type declarations.
lib/mocompiler.js(192,42): error TS2339: Property 'total' does not exist on type 'Object'.
lib/mocompiler.js(198,3): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Buffer'.
No index signature with a parameter of type 'string' was found on type 'Buffer'.
lib/mocompiler.js(201,3): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Buffer'.
No index signature with a parameter of type 'string' was found on type 'Buffer'.
lib/mocompiler.js(204,3): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Buffer'.
No index signature with a parameter of type 'string' was found on type 'Buffer'.
lib/mocompiler.js(207,3): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Buffer'.
No index signature with a parameter of type 'string' was found on type 'Buffer'.
lib/mocompiler.js(210,3): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Buffer'.
No index signature with a parameter of type 'string' was found on type 'Buffer'.
lib/mocompiler.js(213,3): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Buffer'.
No index signature with a parameter of type 'string' was found on type 'Buffer'.
lib/mocompiler.js(216,3): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Buffer'.
No index signature with a parameter of type 'string' was found on type 'Buffer'.
lib/mocompiler.js(222,5): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Buffer'.
No index signature with a parameter of type 'string' was found on type 'Buffer'.
lib/mocompiler.js(223,5): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Buffer'.
No index signature with a parameter of type 'string' was found on type 'Buffer'.
lib/mocompiler.js(224,5): error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'Buffer'.
lib/mocompiler.js(231,5): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Buffer'.
No index signature with a parameter of type 'string' was found on type 'Buffer'.
lib/mocompiler.js(232,5): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Buffer'.
No index signature with a parameter of type 'string' was found on type 'Buffer'.
lib/mocompiler.js(233,5): error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type 'Buffer'.
Try `npm i --save-dev @types/encoding` if it exists or add a new declaration (.d.ts) file containing `declare module 'encoding';`
lib/moparser.js(86,33): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'.
lib/moparser.js(88,35): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'.
lib/moparser.js(93,33): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'.
lib/moparser.js(95,35): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'.
lib/moparser.js(112,3): error TS2322: Type 'null' is not assignable to type 'Buffer'.
lib/moparser.js(131,3): error TS2322: Type 'Object' is not assignable to type 'undefined'.
lib/moparser.js(131,37): error TS2345: Argument of type 'Buffer' is not assignable to parameter of type 'string'.
lib/moparser.js(145,3): error TS2322: Type 'string[]' is not assignable to type 'string'.
lib/moparser.js(147,21): error TS2339: Property 'shift' does not exist on type 'string'.
lib/moparser.js(152,17): error TS2339: Property 'join' does not exist on type 'string'.
lib/moparser.js(155,3): error TS2322: Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
lib/moparser.js(163,3): error TS2322: Type 'string[]' is not assignable to type 'string'.
lib/moparser.js(164,3): error TS7008: Member 'msgstr' implicitly has an 'any[]' type.
lib/moparser.js(164,34): error TS2769: No overload matches this call.
Overload 1 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.
  Argument of type 'string | never[]' is not assignable to parameter of type 'ConcatArray<never>'.
    Type 'string' is not assignable to type 'ConcatArray<never>'.
Overload 2 of 2, '(...items: ConcatArray<never>[]): never[]', gave the following error.
  Argument of type 'string | never[]' is not assignable to parameter of type 'ConcatArray<never>'.
    Type 'string' is not assignable to type 'ConcatArray<never>'.
lib/moparser.js(166,8): error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{}'.
lib/moparser.js(167,5): error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{}'.
lib/moparser.js(170,3): error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{}'.
lib/moparser.js(186,39): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'.
lib/moparser.js(191,36): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'.
lib/moparser.js(196,46): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'.
lib/moparser.js(201,49): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'.
Try `npm i --save-dev @types/encoding` if it exists or add a new declaration (.d.ts) file containing `declare module 'encoding';`
lib/pocompiler.js(15,33): error TS7006: Parameter 'options' implicitly has an 'any' type.
lib/pocompiler.js(31,15): error TS2339: Property 'translations' does not exist on type 'Object'.
lib/pocompiler.js(31,42): error TS2339: Property 'translations' does not exist on type 'Object'.
lib/pocompiler.js(33,9): error TS2339: Property 'headers' does not exist on type 'Object'.
lib/pocompiler.js(39,14): error TS2538: Type 'undefined' cannot be used as an index type.
lib/pocompiler.js(41,7): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
No index signature with a parameter of type 'string' was found on type '{}'.
lib/pocompiler.js(47,15): error TS2339: Property 'headers' does not exist on type 'Object'.
lib/pocompiler.js(50,19): error TS2339: Property 'foldLength' does not exist on type '{}'.
lib/pocompiler.js(54,19): error TS2339: Property 'escapeCharacters' does not exist on type '{}'.
lib/pocompiler.js(58,19): error TS2339: Property 'sort' does not exist on type '{}'.
lib/pocompiler.js(62,19): error TS2339: Property 'eol' does not exist on type '{}'.
lib/pocompiler.js(78,9): error TS7034: Variable 'lines' implicitly has type 'any[]' in some locations where its type cannot be determined.
lib/pocompiler.js(97,10): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Object'.
No index signature with a parameter of type 'string' was found on type 'Object'.
lib/pocompiler.js(101,5): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Object'.
No index signature with a parameter of type 'string' was found on type 'Object'.
lib/pocompiler.js(101,50): error TS7006: Parameter 'line' implicitly has an 'any' type.
lib/pocompiler.js(106,10): error TS7005: Variable 'lines' implicitly has an 'any[]' type.
lib/pocompiler.js(106,35): error TS2339: Property 'eol' does not exist on type '{}'.
lib/pocompiler.js(119,28): error TS2339: Property 'msgctxt' does not exist on type 'Object'.
lib/pocompiler.js(119,45): error TS2339: Property 'msgctxt' does not exist on type 'Object'.
lib/pocompiler.js(120,26): error TS2339: Property 'msgid' does not exist on type 'Object'.
lib/pocompiler.js(120,41): error TS2339: Property 'msgid' does not exist on type 'Object'.
lib/pocompiler.js(121,32): error TS2339: Property 'msgid_plural' does not exist on type 'Object'.
lib/pocompiler.js(121,54): error TS2339: Property 'msgid_plural' does not exist on type 'Object'.
lib/pocompiler.js(122,9): error TS7005: Variable 'msgstr' implicitly has an 'any[]' type.
lib/pocompiler.js(122,37): error TS2339: Property 'msgstr' does not exist on type 'Object'.
lib/pocompiler.js(122,53): error TS2339: Property 'msgstr' does not exist on type 'Object'.
lib/pocompiler.js(123,27): error TS2339: Property 'comments' does not exist on type 'Object'.
lib/pocompiler.js(123,45): error TS2339: Property 'comments' does not exist on type 'Object'.
lib/pocompiler.js(146,38): error TS2339: Property 'eol' does not exist on type '{}'.
lib/pocompiler.js(163,9): error TS2339: Property 'foldLength' does not exist on type '{}'.
lib/pocompiler.js(163,21): error TS2339: Property 'eol' does not exist on type '{}'.
lib/pocompiler.js(163,26): error TS2339: Property 'escapeCharacters' does not exist on type '{}'.
lib/pocompiler.js(208,44): error TS2339: Property 'headers' does not exist on type 'Object'.
lib/pocompiler.js(210,45): error TS2339: Property 'charset' does not exist on type 'Object'.
lib/pocompiler.js(217,15): error TS2339: Property 'charset' does not exist on type 'Object'.
lib/pocompiler.js(218,15): error TS2339: Property 'headers' does not exist on type 'Object'.
lib/pocompiler.js(225,14): error TS2314: Generic type 'Array<T>' requires 1 type argument(s).
lib/pocompiler.js(228,7): error TS7034: Variable 'response' implicitly has type 'any[]' in some locations where its type cannot be determined.
lib/pocompiler.js(231,16): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Object'.
No index signature with a parameter of type 'string' was found on type 'Object'.
lib/pocompiler.js(235,17): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Object'.
No index signature with a parameter of type 'string' was found on type 'Object'.
lib/pocompiler.js(236,18): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Object'.
No index signature with a parameter of type 'string' was found on type 'Object'.
lib/pocompiler.js(244,21): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Object'.
No index signature with a parameter of type 'string' was found on type 'Object'.
lib/pocompiler.js(248,11): error TS2339: Property 'sort' does not exist on type '{}'.
lib/pocompiler.js(252,18): error TS7005: Variable 'response' implicitly has an 'any[]' type.
lib/pocompiler.js(254,18): error TS7005: Variable 'response' implicitly has an 'any[]' type.
lib/pocompiler.js(267,36): error TS2339: Property 'translations' does not exist on type 'Object'.
lib/pocompiler.js(267,68): error TS2339: Property 'translations' does not exist on type 'Object'.
lib/pocompiler.js(270,57): error TS2339: Property 'translations' does not exist on type 'Object'.
lib/pocompiler.js(273,26): error TS2339: Property 'obsolete' does not exist on type 'Object'.
lib/pocompiler.js(274,55): error TS2339: Property 'obsolete' does not exist on type 'Object'.
lib/pocompiler.js(280,11): error TS2339: Property 'eol' does not exist on type '{}'.
lib/pocompiler.js(283,40): error TS2339: Property 'headers' does not exist on type 'Object'.
lib/pocompiler.js(286,19): error TS2339: Property 'charset' does not exist on type 'Object'.
lib/pocompiler.js(286,54): error TS2339: Property 'charset' does not exist on type 'Object'.
lib/pocompiler.js(290,71): error TS2339: Property 'charset' does not exist on type 'Object'.

Try `npm i --save-dev @types/encoding` if it exists or add a new declaration (.d.ts) file containing `declare module 'encoding';`
lib/poparser.js(9,65): error TS2300: Duplicate identifier 'Options'.
lib/poparser.js(22,63): error TS2300: Duplicate identifier 'Options'.
lib/poparser.js(34,65): error TS2300: Duplicate identifier 'Options'.
lib/poparser.js(43,3): error TS7008: Member '_lex' implicitly has an 'any[]' type.
lib/poparser.js(53,46): error TS2345: Argument of type 'Buffer' is not assignable to parameter of type 'string'.
lib/poparser.js(95,40): error TS7006: Parameter 'buf' implicitly has an 'any' type.
lib/poparser.js(170,24): error TS2339: Property 'obsolete' does not exist on type '{}'.
lib/poparser.js(179,46): error TS2339: Property 'value' does not exist on type '{}'.
lib/poparser.js(180,22): error TS2339: Property 'value' does not exist on type '{}'.
lib/poparser.js(183,22): error TS2339: Property 'value' does not exist on type '{}'.
lib/poparser.js(190,26): error TS2339: Property 'value' does not exist on type '{}'.
lib/poparser.js(193,26): error TS2339: Property 'value' does not exist on type '{}'.
lib/poparser.js(196,26): error TS2339: Property 'value' does not exist on type '{}'.
lib/poparser.js(199,26): error TS2339: Property 'value' does not exist on type '{}'.
lib/poparser.js(203,34): error TS2339: Property 'quote' does not exist on type '{}'.
lib/poparser.js(209,24): error TS2339: Property 'value' does not exist on type '{}'.
lib/poparser.js(216,27): error TS2339: Property 'value' does not exist on type '{}'.
lib/poparser.js(217,96): error TS2339: Property 'value' does not exist on type '{}'.
lib/poparser.js(219,17): error TS2339: Property 'lineNumber' does not exist on type 'SyntaxError'.
lib/poparser.js(226,22): error TS2339: Property 'value' does not exist on type '{}'.
lib/poparser.js(243,32): error TS2339: Property 'length' does not exist on type 'Object'.
lib/poparser.js(244,21): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(245,25): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(246,28): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(247,32): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(249,21): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(250,18): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(264,10): error TS2339: Property 'forEach' does not exist on type 'Object'.
lib/poparser.js(264,18): error TS7006: Parameter 'node' implicitly has an 'any' type.
lib/poparser.js(279,19): error TS7006: Parameter 'line' implicitly has an 'any' type.
lib/poparser.js(282,34): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.
lib/poparser.js(285,34): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.
lib/poparser.js(288,29): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.
lib/poparser.js(291,33): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.
lib/poparser.js(296,35): error TS2345: Argument of type 'any' is not assignable to parameter of type 'never'.
lib/poparser.js(303,11): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ translator: never[]; extracted: never[]; reference: never[]; flag: never[]; previous: never[]; }'.
No index signature with a parameter of type 'string' was found on type '{ translator: never[]; extracted: never[]; reference: never[]; flag: never[]; previous: never[]; }'.
lib/poparser.js(303,27): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ translator: never[]; extracted: never[]; reference: never[]; flag: never[]; previous: never[]; }'.
No index signature with a parameter of type 'string' was found on type '{ translator: never[]; extracted: never[]; reference: never[]; flag: never[]; previous: never[]; }'.
lib/poparser.js(304,27): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ translator: never[]; extracted: never[]; reference: never[]; flag: never[]; previous: never[]; }'.
No index signature with a parameter of type 'string' was found on type '{ translator: never[]; extracted: never[]; reference: never[]; flag: never[]; previous: never[]; }'.
lib/poparser.js(320,32): error TS2339: Property 'length' does not exist on type 'Object'.
lib/poparser.js(321,9): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(323,14): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(325,11): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(326,18): error TS2339: Property 'obsolete' does not exist on type '{ key: any; }'.
lib/poparser.js(328,16): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(329,18): error TS2339: Property 'comments' does not exist on type '{ key: any; }'.
lib/poparser.js(329,29): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(331,16): error TS2339: Property 'value' does not exist on type '{ key: any; }'.
lib/poparser.js(333,16): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(334,16): error TS2339: Property 'value' does not exist on type '{ key: any; }'.
lib/poparser.js(334,25): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(353,32): error TS2339: Property 'length' does not exist on type 'Object'.
lib/poparser.js(354,9): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(355,20): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(356,21): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(357,16): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(359,16): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(361,11): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(362,18): error TS2339: Property 'obsolete' does not exist on type '{ msgid: any; }'.
lib/poparser.js(366,18): error TS2339: Property 'msgctxt' does not exist on type '{ msgid: any; }'.
lib/poparser.js(370,18): error TS2339: Property 'comments' does not exist on type '{ msgid: any; }'.
lib/poparser.js(373,11): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(373,43): error TS2339: Property 'comments' does not exist on type '{ msgid: any; }'.
lib/poparser.js(374,18): error TS2339: Property 'comments' does not exist on type '{ msgid: any; }'.
lib/poparser.js(374,29): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(380,16): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(383,104): error TS2339: Property 'msgctxt' does not exist on type '{ msgid: any; } & Record<"msgid_plural", unknown>'.
lib/poparser.js(386,18): error TS2339: Property 'msgid_plural' does not exist on type '{ msgid: any; }'.
lib/poparser.js(386,33): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(389,11): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(389,34): error TS18048: 'lastNode' is possibly 'undefined'.
lib/poparser.js(389,43): error TS2339: Property 'comments' does not exist on type '{ msgid: any; }'.
lib/poparser.js(390,9): error TS18048: 'lastNode' is possibly 'undefined'.
lib/poparser.js(390,18): error TS2339: Property 'comments' does not exist on type '{ msgid: any; }'.
lib/poparser.js(390,29): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(395,16): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(397,18): error TS2339: Property 'msgstr' does not exist on type '{ msgid: any; }'.
lib/poparser.js(397,37): error TS2339: Property 'msgstr' does not exist on type '{ msgid: any; }'.
lib/poparser.js(397,58): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(400,11): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(400,34): error TS18048: 'lastNode' is possibly 'undefined'.
lib/poparser.js(400,43): error TS2339: Property 'comments' does not exist on type '{ msgid: any; }'.
lib/poparser.js(401,9): error TS18048: 'lastNode' is possibly 'undefined'.
lib/poparser.js(401,18): error TS2339: Property 'comments' does not exist on type '{ msgid: any; }'.
lib/poparser.js(401,29): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(423,5): error TS2339: Property 'msgid' does not exist on type 'Object'.
lib/poparser.js(424,5): error TS2339: Property 'msgid_plural' does not exist on type 'Object'.
lib/poparser.js(425,5): error TS2339: Property 'msgstr' does not exist on type 'Object'.
lib/poparser.js(435,16): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Object'.
No index signature with a parameter of type 'string' was found on type 'Object'.
lib/poparser.js(462,32): error TS2339: Property 'length' does not exist on type 'Object'.
lib/poparser.js(463,15): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(465,9): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(466,18): error TS2339: Property 'obsolete' does not exist on type '{ charset: string; headers: undefined; translations: {}; }'.
lib/poparser.js(467,15): error TS2339: Property 'obsolete' does not exist on type '{ charset: string; headers: undefined; translations: {}; }'.
lib/poparser.js(470,18): error TS2339: Property 'obsolete' does not exist on type '{ charset: string; headers: undefined; translations: {}; }'.
lib/poparser.js(471,15): error TS2339: Property 'obsolete' does not exist on type '{ charset: string; headers: undefined; translations: {}; }'.
lib/poparser.js(474,14): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(476,13): error TS2339: Property 'obsolete' does not exist on type '{ charset: string; headers: undefined; translations: {}; }'.
lib/poparser.js(476,31): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(476,50): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(481,10): error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{}'.
lib/poparser.js(482,7): error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{}'.
lib/poparser.js(485,40): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(486,7): error TS2322: Type 'Object' is not assignable to type 'undefined'.
lib/poparser.js(486,35): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(490,25): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(492,5): error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{}'.
lib/poparser.js(492,33): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(492,52): error TS7053: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'Object'.
No index signature with a parameter of type 'number' was found on type 'Object'.
lib/poparser.js(518,63): error TS2300: Duplicate identifier 'Options'.
lib/poparser.js(528,3): error TS7008: Member '_cache' implicitly has an 'any[]' type.
lib/poparser.js(531,43): error TS2339: Property 'initialTreshold' does not exist on type 'TransformOptions'.
lib/poparser.js(533,18): error TS2345: Argument of type 'this' is not assignable to parameter of type 'Transform'.
Type 'PoParserTransform' is missing the following properties from type 'Transform': _transformState, allowHalfOpen, destroyed, readable, and 72 more.
lib/poparser.js(534,8): error TS2339: Property '_writableState' does not exist on type 'PoParserTransform'.
lib/poparser.js(535,8): error TS2339: Property '_readableState' does not exist on type 'PoParserTransform'.
lib/poparser.js(544,52): error TS7006: Parameter 'chunk' implicitly has an 'any' type.
lib/poparser.js(544,59): error TS7006: Parameter 'encoding' implicitly has an 'any' type.
lib/poparser.js(544,69): error TS7006: Parameter 'done' implicitly has an 'any' type.
lib/poparser.js(565,5): error TS2322: Type 'Parser' is not assignable to type 'boolean'.
lib/poparser.js(594,20): error TS2339: Property '_lexer' does not exist on type 'boolean'.
lib/poparser.js(594,40): error TS2339: Property '_toString' does not exist on type 'boolean'.
lib/poparser.js(610,48): error TS7006: Parameter 'done' implicitly has an 'any' type.
lib/poparser.js(618,5): error TS2322: Type 'Parser' is not assignable to type 'boolean'.
lib/poparser.js(623,20): error TS2339: Property '_lexer' does not exist on type 'boolean'.
lib/poparser.js(623,40): error TS2339: Property '_toString' does not exist on type 'boolean'.
lib/poparser.js(634,10): error TS2339: Property 'push' does not exist on type 'PoParserTransform'.
lib/poparser.js(634,28): error TS2339: Property '_finalize' does not exist on type 'true'.
lib/poparser.js(634,51): error TS2339: Property '_lex' does not exist on type 'true'.
lib/shared.js(37,9): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
No index signature with a parameter of type 'string' was found on type '{}'.
lib/shared.js(52,33): error TS7053: Element implicitly has an 'any' type because expression of type '"Plural-Forms"' can't be used to index type 'Object'.
Property 'Plural-Forms' does not exist on type 'Object'.
lib/shared.js(80,17): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Object'.
No index signature with a parameter of type 'string' was found on type 'Object'.
lib/shared.js(155,33): error TS2339: Property 'msgid' does not exist on type 'Object'.
lib/shared.js(155,50): error TS2339: Property 'msgid' does not exist on type 'Object'.

Copy link
Collaborator Author

@erikyo erikyo left a comment

Choose a reason for hiding this comment

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

those needs to be fixed

lib/poparser.js Outdated Show resolved Hide resolved
lib/pocompiler.js Outdated Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
- revert unneeded changes in package.json
- revert files moved to src
- linting
@erikyo
Copy link
Collaborator Author

erikyo commented Apr 11, 2024

About the jsDoc i did another branch where i implemented strict js type checking reducing type check issues (from > 400 to less than 50), but there is still a lot of work to be done though (some sections are really difficult to type without typescript).

it should look like this:
https://github.com/erikyo/gettext-parser/blob/eb797c68e64c86d0feda41d1043a94a6e859429e/lib/pocompiler.js#L22-L43

I also think in that way could close some issues such as the #29 that which I actually believe that is forced conversion between array and string, and other issues that are really related to js duck typing

I would like to point out that I just use the tests to make sure that everything is OK so I am pretty sure that everything works exactly as before

src/moparser.js Outdated Show resolved Hide resolved
@smhg
Copy link
Owner

smhg commented Apr 15, 2024

About the jsDoc i did another branch where i implemented strict js type checking reducing type check issues (from > 400 to less than 50), but there is still a lot of work to be done though (some sections are really difficult to type without typescript).

it should look like this:
https://github.com/erikyo/gettext-parser/blob/eb797c68e64c86d0feda41d1043a94a6e859429e/lib/pocompiler.js#L22-L43

You already lost me with those.
Let's first clean up the current code with a pre-TS PR if you want. That would reduce the changed files by a lot. This can also already be released immediatly.
We can discuss types in a second step.

@erikyo
Copy link
Collaborator Author

erikyo commented Apr 15, 2024

We can discuss types in a second step.

That the reason why i moved the changes into a separate branch (https://github.com/erikyo/gettext-parser/tree/enforcing-types), they are important to me and I would not like to lose them, but I understand that they are not part of the subject of this PR.

I will create a dedicated pr for that, where we could address the transition to es2015 by creating classes and their related types

@erikyo
Copy link
Collaborator Author

erikyo commented Apr 15, 2024

I did a small test with another repo and this other one that are using the gettext-parser types and it the first one works flawlessly simply replacing the line "@types/gettext-parser": "^4.0.4", with "gettext-parser": "*"

In the second case as for the most of the users, however, it will suffice to remove the line "@types/gettext-parser": "^4.0.4" since the repo already provides types, so the update will be very smooth

…rts the types, because index.js is in the repo root)

fix msg_plural that despite the name is a "string" and not a "string[]"
@erikyo
Copy link
Collaborator Author

erikyo commented Apr 20, 2024

Hi @smhg, friendly ping on this since I haven't heard from you in a while, I modified the pr and also tested it on a couple of repos I was using it on and it works perfectly. If you have any doubts about anything tell me how to proceed

@erikyo
Copy link
Collaborator Author

erikyo commented Apr 28, 2024

@smhg, I'm writing to provide an update regarding the pull request I opened. Since I haven't heard back from you in over a week, I've decided to proceed independently and have completely rewritten the module in TypeScript to adapt it to my needs.

Therefore, I would like to close the original pull request and publish my fork. If you have any questions or comments, please feel free to let me know otherwise i will proceed in this direction.

@smhg
Copy link
Owner

smhg commented Apr 30, 2024

Hi @erikyo! Thank you for following up on this. I'm sorry I wasn't able to get back earlier.

I am not sure we are talking about the same things though.
I meant to ask if you could create a new PR with the minor improvements your initial PR contained (typos, moving /lib to /src,...). Some of those I mentioned in the comments, but I basically mean everything unrelated to TS itself.
I highly value those too + afterwards we can have a very clean TS PR (basically what remains in this PR).
Can you have a look at that first? So please do send a new PR with all those unrelated changes.

@erikyo
Copy link
Collaborator Author

erikyo commented Apr 30, 2024

Certainly! I was anticipating your approval of this PR before proceeding with additional small PRs to address the other minor inaccuracies (and at this point I think it is the best thing to do to avoid merge conflicts).

My plan is to submit one PR per issue, ensuring clarity and transparency throughout the process. I can create a tracking issue if you want (those with bullet points linking to the different pr) to wrap all the changes in a single issue. I apologize for any confusion, but this PR needed to implement significant changes to achieve the necessary improvements.

@erikyo erikyo mentioned this pull request Apr 30, 2024
10 tasks
@erikyo
Copy link
Collaborator Author

erikyo commented May 1, 2024

I think perhaps the best thing is to create a development branch on which to merge the changes listed here until they are all completed. Then when finished you can rebase the development branch on master

What do you think? this way we can operate safely without modifying the main branch

@erikyo erikyo changed the base branch from master to development May 3, 2024 10:53
@erikyo erikyo merged commit f3d5cf8 into smhg:development May 4, 2024
4 checks passed
@erikyo erikyo deleted the #80/strictly-typed branch May 4, 2024 21:54
@erikyo erikyo mentioned this pull request May 6, 2024
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.

Typescript update
3 participants