-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
WithFieldValue mangles Class Types #2291
Comments
Issue was opened with an invalid reproduction link. Please make sure the repository is a valid, publicly-accessible github repository, and make sure the url is complete (example: https://github.com/googleapis/google-cloud-node) |
If interested I can open a PR to update the documentation with my fixes. However, it really does feel like |
Link should be good now. Hard to manage multiple revisions in a gist. |
Hi @rgant, thank you for raising this issue. As you noticed, T is passed down only if it is a primitive data type, otherwise, it needs to wrap it with |
But then TypeScript doesn't understand that If |
seems like the bot incorrectly closed this issue |
Issue was opened with an invalid reproduction link. Please make sure the repository is a valid, publicly-accessible github repository, and make sure the url is complete (example: https://github.com/googleapis/google-cloud-node) |
Issue was opened with an invalid reproduction link. Please make sure the repository is a valid, publicly-accessible github repository, and make sure the url is complete (example: https://github.com/googleapis/google-cloud-node) |
I tried adding another link to a repo to make the bot happy hopefully. |
@rgant, This is an interesting issue. If I understand, the general request is that the type
I'm not aware of how The runtime check |
Issue was opened with an invalid reproduction link. Please make sure the repository is a valid, publicly-accessible github repository, and make sure the url is complete (example: https://github.com/googleapis/google-cloud-node) |
I think there are relatively few types that can both appear in a Firestore document and payload without erring. Could we add nodejs-firestore/types/firestore.d.ts Line 79 in c6c85b6
Or add some sort of "Classy" type like |
Updated the description to stop the auto-close for "invalid link" |
I'm not sure if I understand. The type(s) passed to the converter (e.g. Post, Date, Author...) may or may not be converted to some other object that is written to the DB. Limiting the solution to Date and Timestamp, doesn't seem like a general solution. Interesting idea too about the "Classy" type, but I think that would make it ignore Author and Class, if they were defined as a class and not a type. I may be able to tweak WithFieldValue to ignore any functions, which would address the issue you're experiencing with Date, and also be a general improvement, I think. |
It is my belief that What I think is wrong is |
Please make sure you have searched for information in the following guides.
A screenshot that you have tested with "Try this API".
Attempting to use
WithFieldValue<Date>
mangles toDate
type such thattsc
no longer recognizes it as a Date. I assume this happens for most other non-primitive values in Firestore documents.Link to repro. A link to a public Github Repository or gist with a minimal reproduction.
https://github.com/rgant/brainfry
https://gist.github.com/rgant/adf3984ebd43c278b716c372412f7109/193be3d9e79f8beafc452a2c814af61883ea9958
A step-by-step description of how to reproduce the issue, based on the linked reproduction.
This all happens when running linters and type checkers in my editor.
A clear and concise description of what the bug is, and what you expected to happen.
Because
WithFieldValue<Post>
climbs inside of theDate
property this results problems with typing as seen on line 63I can fix this (with some ugly unnecessary code my throwing a
TypeError
if the parameter isn't aDate
nor aFieldValue
.A clear and concise description WHY you expect this behavior, i.e., was it a recent change, there is documentation that points to this behavior, etc. **
I feel like the documentation update is better, but doesn't actually cover a real world case. Maybe I'm just strange but I wouldn't use a number of milliseconds in a front end application where I expect to display a date and time of a post. I would use a JavaScript
Date
(orTemporal
).The text was updated successfully, but these errors were encountered: