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

Migrate isValid function to TS #2308

Merged
merged 4 commits into from Sep 16, 2021
Merged

Migrate isValid function to TS #2308

merged 4 commits into from Sep 16, 2021

Conversation

rikkalo
Copy link
Contributor

@rikkalo rikkalo commented Mar 10, 2021

requiredArgs(1, arguments)

var date = toDate(dirtyDate)
return !isNaN(date)
if (!(dirtyDate instanceof Date) && typeof dirtyDate !== 'number') {
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 it would be better to use isDate here since it handles an iframe passing edge case not covered by instanceof alone.

Copy link
Member

Choose a reason for hiding this comment

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

Good point! 👍

@tan75 tan75 mentioned this pull request Aug 27, 2021
16 tasks
Copy link
Contributor

@tan75 tan75 left a comment

Choose a reason for hiding this comment

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

Thank you! 👍

@fturmel
Copy link
Member

fturmel commented Sep 15, 2021

@tan75 I think that last change was a mistake. The predicate is Date | number works great. The problem I had pointed out a while ago in other comments was that is Date was not sufficient.

With predicate, we narrow the result down to Date or number:
Screen Shot 2021-09-15 at 8 20 43 AM

With boolean return, type is still unknown:
Screen Shot 2021-09-15 at 8 20 08 AM

@fturmel
Copy link
Member

fturmel commented Sep 15, 2021

As I pointed out here #2551 (comment), the remaining problem is with the jsdocs / type generator system for these type guards in isValid and isDate to be correctly carried to typings.d.ts.

How to write the jsdocs part: microsoft/TypeScript#25127 (comment)

@kossnocorp kossnocorp merged commit 237f831 into master Sep 16, 2021
@kossnocorp kossnocorp deleted the migrate-ts-isValid branch September 16, 2021 05:20
tan75 added a commit to janziemba/date-fns that referenced this pull request Dec 27, 2021
Co-authored-by: Tetiana <ttobin@protonmail.ch>
Co-authored-by: Sasha Koss <koss@nocorp.me>
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.

Migrate isValid function
4 participants