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

Chore/typescript conversion/27 #33

Merged
merged 7 commits into from
Nov 30, 2021
Merged

Conversation

waylandli
Copy link

@waylandli waylandli commented Nov 24, 2021

Problem

[Github Issues #27 ]

Converted the files listed in the issues into typescript without using any

Change summary:

  • Each file is changed to typescript

Steps to Verify:

Running all the tests should still work

Copy link
Member

@wilwade wilwade left a comment

Choose a reason for hiding this comment

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

Did a quick pass. Haven't looked at everything yet.

lib/codec/plain.ts Outdated Show resolved Hide resolved
lib/codec/plain.ts Outdated Show resolved Hide resolved
lib/codec/plain.ts Outdated Show resolved Hide resolved
switch (type) {
case "BOOLEAN":
return encodeValues_BOOLEAN(values as Array<boolean>);
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we could remove the as ... on each of these and just have encodeValues do the work. Thoughts?

Copy link
Author

Choose a reason for hiding this comment

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

I tried removing the as ... but have run into issues on typescript not liking that very much. Similar issue to Shannons comment below

Copy link
Member

Choose a reason for hiding this comment

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

That works. We are saying it is that type, so I'm ok with it.

lib/codec/rle.ts Outdated
@@ -42,7 +43,7 @@ exports.encodeValues = function(type, values, opts) {
case 'BOOLEAN':
case 'INT32':
case 'INT64':
values = values.map((x) => parseInt(x, 10));
values = values.map((x) => parseInt(x as unknown as string, 10)); // We should fix unknown as string
Copy link
Member

Choose a reason for hiding this comment

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

I think the correct fix might be to set vales: Array at the top and have a helper function that converts from unknown to a parsed int.

Also I thought we fixed all the places where we have Int64 to use bigint instead.

Copy link
Author

Choose a reason for hiding this comment

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

Implemented helper function to fix. Not sure about the Int64 but I do know that the toPrimitives that I worked on return number if the value given is number but bigint otherwise if thats what you were referencing

Comment on lines 7 to 8
deflate: Function,
inflate: Function
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we can get more specific than just Function here

Suggested change
deflate: Function,
inflate: Function
deflate: <T>(value: Buffer | string | ArrayBuffer | Uint8Array) => T;
inflate: <T>(value: T) => Buffer | string | ArrayBuffer | Uint8Array;

Copy link
Collaborator

Choose a reason for hiding this comment

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

@wilwade I worked with @waylandli on this and it's not as simple as it might seem, because the union type does not work here, and it doesn't even work to declare the functions as types and use a union of those. So it's going to need more of a refactor than at first blush. I suggest we punt to a later PR.

Copy link
Member

Choose a reason for hiding this comment

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

I'm good with that punt. Sounds like the interface there is a bit problematic and might take some code changes (beyond the conversion)

lib/custom.d.ts Show resolved Hide resolved
test/codec_plain.test.js Outdated Show resolved Hide resolved
test/codec_rle.js Outdated Show resolved Hide resolved
test/types.js Outdated Show resolved Hide resolved
Copy link
Member

@wilwade wilwade left a comment

Choose a reason for hiding this comment

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

One last type update you could make, but otherwise good to go!

};

export const decodeValues = function (
type: string,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
type: string,
type: ValidValueTypes | string,

switch (type) {
case "BOOLEAN":
return encodeValues_BOOLEAN(values as Array<boolean>);
Copy link
Member

Choose a reason for hiding this comment

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

That works. We are saying it is that type, so I'm ok with it.

@waylandli waylandli merged commit a82975b into main Nov 30, 2021
@waylandli waylandli deleted the chore/typescript-conversion/27 branch November 30, 2021 18:20
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.

4 participants