Skip to content

Conversation

@mhmd-azeez
Copy link
Contributor

@mhmd-azeez mhmd-azeez requested a review from bhelx October 23, 2024 15:57
@bhelx
Copy link
Contributor

bhelx commented Oct 23, 2024

I need to study this a bit more. On the one hand, there is going to be some complication with this change and i get that. On the other, this is a lot of code, and moving some of the rendering to the helpers adds some indirection. I also feel like there is a lot of repetitive code in here and there might be some simpler ways to do this.

if (property.$ref) {
tp = property.$ref.name
} else if (property.additionalProperties) {
tp = `Record<string, ${toTypeScriptType(property.additionalProperties)}>`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use Record over Map? my understanding is Record is pretty limited to the key and value types it can hold.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think i see the logic here. looks like keys can only really be strings anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have a strong opinion here, but it seems like Record has a more straightforward path for json serialization: https://stackoverflow.com/questions/50153172/how-to-serialize-a-map-in-javascript

if (!obj) return result

for (const [key, value] of Object.entries(obj)) {
result[key] = cast(value);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure it's safe to mutate this and we may need to copy. we'll be changing the type of a property that a user my still be holding right?

Copy link
Contributor Author

@mhmd-azeez mhmd-azeez Oct 24, 2024

Choose a reason for hiding this comment

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

We are mutating the local copy result, so i think we should be fine

@mhmd-azeez
Copy link
Contributor Author

@bhelx

On the other, this is a lot of code, and moving some of the rendering to the helpers adds some indirection. I also feel like there is a lot of repetitive code in here and there might be some simpler ways to do this.

Yeah I agree, I went ahead and refactored the code a bit

@bhelx
Copy link
Contributor

bhelx commented Oct 25, 2024

Putting this feature on ice for a little bit

@bhelx bhelx marked this pull request as draft October 25, 2024 14:23
@mhmd-azeez
Copy link
Contributor Author

Closing in favor of #37

@mhmd-azeez mhmd-azeez closed this Oct 31, 2024
@bhelx bhelx mentioned this pull request Nov 1, 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.

2 participants