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
isDate() type guard #1907
Comments
hi @BarryThePenguin! I think this may be related but I might be wrong -- @kossnocorp is working on this typescriptify branch. When it's finished, this |
I filed a similar issue about @imballinst, the file you linked still returns boolean, which means it might not act as a typeguard. TS might infer that from Moreover, for the code you've linked, I would specify the incoming type as |
Thanks @icehaunter , I'll check it out. |
@icehaunter ah, gotcha! Yes, that is a great point, I didn't see that before. I 💯 agree with the part of being explicit, it's really useful for assertions in a code-branch. |
any update for this issue?? |
This should be fixed in the recent Typescript-ifying effort, I think? Lines 39 to 47 in b500440
|
@adenvt @imballinst |
Hey @tan75 ! |
I just investigated this. While the type guard is implemented in the Some changes would have to be made to that system so it understands TS type guards but doesn't mess up documentation or Flow types generation. Maybe by introducing a custom jsdoc tag that would take precedent over Lines 15 to 16 in ea3f050
Line 39 in ea3f050
Line 636 in ea3f050
|
Also regarding #1880, I don't think See the truth table in the docs: https://date-fns.org/docs/isValid |
Why is it closed? It still returns boolean instead of Date object. In this generated file is boolean returned: and in this definition it is fine: Lines 39 to 47 in b500440
It is probably due to this typescript generate definition: https://github.com/date-fns/date-fns/blob/b500440132b69fdf2b430743cf86bbc929b60307/scripts/build/_lib/typings/typeScript.js#L142C57-L142C57 |
Is it possible to add a type guard for
isDate()
in the TypeScript definitions?I looked at previous issues and couldn't see any previous discussion. It doesn't look like it was considered in the implementation #754
I looked at putting a PR together, but wasn't confident making changes to the script that builds the type definitions
The text was updated successfully, but these errors were encountered: