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

[typescript-migration] calendar.jsx and index.jsx #4766

Merged
merged 5 commits into from
May 16, 2024

Conversation

yuki0410-dev
Copy link
Contributor

name: Migrate calendar.jsx and index.jsx

Description

Linked issue: #4700

Changes calendar.jsx and index.jsx was migrated to ts

Contribution checklist

  • I have followed the contributing guidelines.
  • I have added sufficient test coverage for my changes.
  • I have formatted my code with Prettier and checked for linting issues with ESLint for code readability.

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

⚠️ This pull request was not sent to the PullRequest network because the pull request is a draft.

@martijnrusschen
Copy link
Member

@yuki0410-dev anything needed to complete this?

@yuki0410-dev
Copy link
Contributor Author

@martijnrusschen
I am working with index.jsx. There is some rework to be done for consistency, etc. I will release the draft after index.js is complete.

Copy link

codecov bot commented May 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.36%. Comparing base (cf820dd) to head (6fe84be).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4766      +/-   ##
==========================================
+ Coverage   96.35%   98.36%   +2.01%     
==========================================
  Files           8        6       -2     
  Lines         959       61     -898     
  Branches      435       19     -416     
==========================================
- Hits          924       60     -864     
+ Misses         35        1      -34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mirus-ua
Copy link
Contributor

mirus-ua commented May 13, 2024

I noticed a lot of changes that replaced randomProp?: type with randomProp?: type | null. IMO, it is better to replace null with undefined in place of usage instead of making all the types wider.

@yuki0410-dev
Copy link
Contributor Author

@mirus-ua
I am glad for your advice.
I agree with unifying the internal types to undefined or null.
However, since the original selected and other props were of type Date | null | undefined, we have modified the related props to Date | null | undefined to maintain compatibility.
If you have any particular concerns, it would be appreciated if you could comment on them in the File changes tab.

@yuki0410-dev
Copy link
Contributor Author

yuki0410-dev commented May 13, 2024

@mirus-ua
I am struggling with the part of index.ts where the onChange type changes due to selectsRange,selectsMultiple Props.
Any good advice would be appreciated.
In my current code, I am using conditional type with reference to @types/react-datepicker, but the type inference does not work well at the point where onChage is called.
Also, I defined some (conditional type) props using type = and tried to inherit them in the interface, but I get a ts(2312) error.
Otherwise, if I declare Props with type instead of interface, the inference works correctly, but it is not consistent because other Props are declared with interface.

@mirus-ua
Copy link
Contributor

@mirus-ua I am struggling with the part of index.ts where the onChange type changes due to selectsRange,selectsMultiple Props. Any good advice would be appreciated. In my current code, I am using conditional type with reference to @types/react-datepicker, but the type inference does not work well at the point where onChage is called. Also, I defined some (conditional type) props using type = and tried to inherit them in the interface, but I get a ts(2312) error. Otherwise, if I declare Props with type instead of interface, the inference works correctly, but it is not consistent because other Props are declared with interface.

Conditional types work well only with type notation, so if the rest is OK and the only concern is consistency, so I suggest migrating to types instead of interfaces, I don't think that someone will be against it (btw I pick type over interface almost always)

@yuki0410-dev
Copy link
Contributor Author

@mirus-ua
Thanks for the advice.
I too use type when writing code in my daily life.
However, when creating libraries, it is more convenient to be able to extend the type on the user side (as I have done in this PR by extending react-onclickoutside), so I was wondering if I could use interface.
For now, I will try to implement it with type, and if there are requests for interface, I will consider it again at a later time.

@yuki0410-dev yuki0410-dev force-pushed the feat/4700_calendar branch 8 times, most recently from 843472f to 42d699c Compare May 14, 2024 15:21
@yuki0410-dev yuki0410-dev marked this pull request as ready for review May 14, 2024 15:23
Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

✅ This pull request was sent to the PullRequest network for review. Expert reviewers are now being matched to your request based on the code's requirements. Stay tuned!

What to expect from this code review:
  • Comments posted to any areas of potential concern or improvement.
  • Detailed feedback or actions needed to resolve issues that are found.
  • Turnaround times vary, but we aim to be swift.

@yuki0410-dev you can click here to see the review status or cancel the code review job.

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

PullRequest Breakdown

Reviewable lines of change

+ 947
- 1,213

87% TSX
10% TypeScript
2% JavaScript (tests)
1% JSON
<1% Other

Type of change

Feature - These changes are adding a new feature or improvement to existing code.
1 Message
⚠️ Due to its size, this pull request will be reviewed by PullRequest staff before being sent to the reviewer network, and the team will reach out if there are any concerns. After this pull request is sent to the network, please be aware that it will likely have a longer turnaround time and require multiple passes from our reviewers.

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

Very nice work tackling this typescript conversion! I left some feedback throughout for you to consider. Most of it is simplification suggestions but I also left some comments around potential regressions.

Image of Joey G Joey G


Reviewed with ❤️ by PullRequest

src/calendar.tsx Show resolved Hide resolved
src/calendar.tsx Show resolved Hide resolved
src/calendar.tsx Outdated Show resolved Hide resolved
src/date_utils.ts Show resolved Hide resolved
{ dateFormat, locale }: { dateFormat: string | string[]; locale?: Locale } = {
dateFormat: "yyyy-MM-dd",
},
date: Date | null | undefined,
Copy link

Choose a reason for hiding this comment

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

I would consider creating a shared type like OptionalDate to remove the duplication in this file.

🔹 Code Reuse (Nice to have)

Image of Joey G Joey G

Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO, we should use prop?: Type over prop: Type | undefined

src/day.tsx Show resolved Hide resolved
src/index.tsx Show resolved Hide resolved
src/index.tsx Show resolved Hide resolved
src/month_year_dropdown.tsx Outdated Show resolved Hide resolved
src/month_year_dropdown_options.tsx Outdated Show resolved Hide resolved
src/year.tsx Show resolved Hide resolved
test/calendar_test.test.js Show resolved Hide resolved
Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

Left a few comments, but going back and looking at the commits one by one, it may be that these changes are more a question for the existing design than your changes.

The separation of commits, as you did, is a helpful tool for reviewers which could be improved a bit by increasing specifics. Eg, rather than "fix linting rules", I generally prefer, "Updated linting rules to include tsx files."

Hope this review helps you.

Image of John G John G


Reviewed with ❤️ by PullRequest

src/calendar.tsx Show resolved Hide resolved
src/calendar.tsx Show resolved Hide resolved
src/calendar.tsx Show resolved Hide resolved
Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

PullRequest reviewed the updates made to #4766 up until the latest commit (429a0cb). No further issues were found.

Reviewed by:

Image of John G John G

@martijnrusschen
Copy link
Member

@mirus-ua can you review this PR as well?

Copy link
Contributor

@mirus-ua mirus-ua left a comment

Choose a reason for hiding this comment

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

First of all, thank you for the big chunk of work and that you wrote a lot of explicit return types it'll help in the future to make changes in a safe way.

I have a few points:

  • prop: Type | null | undefined can be simplified to prop?: Type | null
  • I don't understand the reason why we replace HTMLDivElemnt with HTMLElement that quite generic and may cause problems for the extension in the future
  • VoidFunction as props looks like it should be replaced with proper typed function with arguments

Edit:
The good idea is to document all changes that even slightly can be called as breaking

package.json Outdated Show resolved Hide resolved
src/date_utils.ts Show resolved Hide resolved
{ dateFormat, locale }: { dateFormat: string | string[]; locale?: Locale } = {
dateFormat: "yyyy-MM-dd",
},
date: Date | null | undefined,
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO, we should use prop?: Type over prop: Type | undefined

src/date_utils.ts Outdated Show resolved Hide resolved
src/calendar.tsx Outdated Show resolved Hide resolved
src/index.tsx Show resolved Hide resolved
src/month_year_dropdown.tsx Outdated Show resolved Hide resolved
src/portal.tsx Outdated Show resolved Hide resolved
src/week_number.tsx Show resolved Hide resolved
tsconfig.json Show resolved Hide resolved
@yuki0410-dev yuki0410-dev force-pushed the feat/4700_calendar branch 2 times, most recently from c9a5a62 to b2b9b8d Compare May 15, 2024 15:33
@yuki0410-dev
Copy link
Contributor Author

@mirus-ua
Thanks for the review.

I don't understand the reason why we replace HTMLDivElemnt with HTMLElement that quite generic and may cause problems for the extension in the future

Changed the HTMLElement type to a concrete type whenever possible.

VoidFunction as props looks like it should be replaced with proper typed function with arguments

We do not think it is necessary to add arguments at this time that are not being used at this time.
(I don't think this is the scope of the TS conversion.)

@yuki0410-dev
Copy link
Contributor Author

prop: Type | null | undefined can be simplified to prop?: Type | null

I use args: Type | undefined and args?: Type explicitly.
The former always requires an argument at call time, whereas the latter does not raise an error if you forget to write the argument.
Since Optional is not a mere shorthand for union type with undefined, we believe that it should be used with the best of intentions.

Also, as for the prop: Type | null | undefined type, @types/react-datepickr used Date | null | undefined for selected props, etc., so we do so to maintain compatibility.
And the part where the value is passed is of a similar type.

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

PullRequest reviewed the updates made to #4766 up until the latest commit (b2b9b8d). No further issues were found.

Reviewed by:

Image of Joey G Joey G

@mirus-ua
Copy link
Contributor

Also, as for the prop: Type | null | undefined type, @types/react-datepickr used Date | null | undefined for selected props, etc., so we do so to maintain compatibility. And the part where the value is passed is of a similar type.

But the optional operator implicitly adds undefined to the union, or I get your point wrong

We do not think it is necessary to add arguments at this time that are not being used at this time.
(I don't think this is the scope of the TS conversion.)

If you say that all these functions don't receive any parameters then OK

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

PullRequest reviewed the updates made to #4766 up until the latest commit (6fe84be). No further issues were found.

Reviewed by:

Image of John G John G

src/with_floating.tsx Show resolved Hide resolved
src/week_number.tsx Show resolved Hide resolved
src/calendar.tsx Show resolved Hide resolved
src/index.tsx Show resolved Hide resolved
@martijnrusschen
Copy link
Member

@yuki0410-dev @mirus-ua is this PR ready to merge?

@mirus-ua
Copy link
Contributor

@yuki0410-dev @mirus-ua is this PR ready to merge?

I don't see any major issues.
Some of the unsolved problems are addressed here #4757

@martijnrusschen martijnrusschen merged commit 610d001 into Hacker0x01:main May 16, 2024
6 checks passed
@yuki0410-dev yuki0410-dev deleted the feat/4700_calendar branch May 16, 2024 13:45
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.

3 participants