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

Chana/migrate analisis component to ts #56

Merged
merged 4 commits into from
Feb 1, 2024

Conversation

juanigaray
Copy link
Collaborator

No description provided.

Copy link
Contributor

@xaiki xaiki left a comment

Choose a reason for hiding this comment

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

please provide better commit messages.
split your code changes to other PR/commits.

@@ -58,7 +58,7 @@ export default function MonthsSlider({
setMonthRange(range);
setDates({ min, max });
},
[],
[globalDates.min, setDates],
Copy link
Contributor

Choose a reason for hiding this comment

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

how is setDates here ? it's a setter not a variable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Setters, as all functions in javascript, are values and their pointers can change. This is why we use useCallback, for instance. If this component were to receive a different setter, it would need to change its callback.

also, this was raising a warning from the linter, and I believe we should address linter warnings.

Copy link
Contributor

Choose a reason for hiding this comment

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

then why aren't we passing setMonthRange ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

setMonthRange is stable by definition. The linter knows this since this PR from 2020. This component cannot know about the stability of its props.

"plugins": [{ "name": "typescript-plugin-css-modules" }]
"plugins": [{ "name": "typescript-plugin-css-modules" }],
"strictNullChecks": true,
"noUncheckedIndexedAccess": true
Copy link
Contributor

Choose a reason for hiding this comment

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

needs better description of why you're enabeling this.

Copy link
Collaborator Author

@juanigaray juanigaray Jan 30, 2024

Choose a reason for hiding this comment

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

Could the documentation do? I could just link https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess. Otherwise I can provide an explanation for why accessing myArray[n], with n being any number, can return undefined and should be typed as such

Copy link
Contributor

Choose a reason for hiding this comment

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

both =)

@@ -27,17 +45,17 @@ export default function Analisis({ min, max, total, tipos, componentes }) {
</div>

<div className={styles.analisisDatos}>
{Object.keys(tipos.byName).map((t, i) => (
{Object.entries(tipos.byName).map(([t, value], i) => (
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a functional change and should go to it's own commit.
as a rule you should refrain to 'better the code' while migrating.

Copy link
Collaborator Author

@juanigaray juanigaray Jan 30, 2024

Choose a reason for hiding this comment

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

I'll keep it in mind in the future, but I believe this change is part of the migration. This does not change any functionality and fixes problems with Typescript.

You see, when you access tipos.byName[t] you don't have a guarantee that that doesn't evaluate to undefined in Typescript. That's because byName isn't a Record<NarrowType, Whatever> but a Record<string, string>, which makes it possible to access byName["someString"] and get undefined.

If I hadn't changed this, I would have had typing errors. In my opinion this change is pertinent to the commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

then the right way is to put it in another commit explaining exactly what you wrote here.

@juanigaray
Copy link
Collaborator Author

juanigaray commented Jan 30, 2024

please provide better commit messages. split your code changes to other PR/commits.

@xaiki I can split the MonthsSlider commit to a new PR but I am having trouble seeing how my commit messages could be better.

So, two questions:

  • Would splitting the commit I mentioned to a new PR be enough for your first request?
  • How would you phrase the commits otherwise?

@xaiki
Copy link
Contributor

xaiki commented Jan 30, 2024

what you've explained here is exactly what should go into the commit history.

Juani Garay added 3 commits January 31, 2024 12:56
Setters, as all functions in javascript, are values and their pointers can change.
If this component were to receive a different setter, it would need to change its callback.
Also, this was raising a warning from the linter, and I believe we should address linter warnings.
When you access tipos.byName[t] you don't have a guarantee that that doesn't evaluate to undefined in Typescript.
That's because byName isn't a Record<NarrowType, Whatever> but a Record<string, string>, which makes it possible to access byName["someString"] and get undefined.
That is why Object.keys was rewritten as Object.entries
@juanigaray juanigaray force-pushed the chana/migrate-analisis-component-to-ts branch from 440dabc to b70aec1 Compare January 31, 2024 16:20
Copy link
Contributor

@xaiki xaiki left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -58,7 +58,7 @@ export default function MonthsSlider({
setMonthRange(range);
setDates({ min, max });
},
[],
[globalDates.min, setDates],
Copy link
Contributor

Choose a reason for hiding this comment

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

then why aren't we passing setMonthRange ?

@juanigaray
Copy link
Collaborator Author

Conversations resolved off-review in group chat.

@juanigaray juanigaray merged commit 612dfc0 into main Feb 1, 2024
2 checks passed
@juanigaray juanigaray deleted the chana/migrate-analisis-component-to-ts branch February 1, 2024 20:17
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