Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

WithFieldValue mangles Class Types #2291

@rgant

Description

@rgant

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 to Date type such that tsc no longer recognizes it as a Date. I assume this happens for most other non-primitive values in Firestore documents.

   63:37  error   Argument of type 'FieldValue | WithFieldValue<Date>' is not assignable to parameter of type 'Date | FieldValue'. ​typescript(2345)
                    Type '{ toString: FieldValue | WithFieldValue<() => string>; toDateString: FieldValue | WithFieldValue<() => string>; toTimeString: FieldValue | WithFieldValue<...>; ... 41 more ...; [Symbol.toPrimitive]: FieldValue | WithFieldValue<...>; }' is not assignable to type 'Date | FieldValue'.
                      Type '{ toString: FieldValue | WithFieldValue<() => string>; toDateString: FieldValue | WithFieldValue<() => string>; toTimeString: FieldValue | WithFieldValue<...>; ... 41 more ...; [Symbol.toPrimitive]: FieldValue | WithFieldValue<...>; }' is not assignable to type 'Date'.
                        Types of property 'toString' are incompatible.
                          Type 'FieldValue | WithFieldValue<() => string>' is not assignable to type '() => string'.
                            Type 'FieldValue' is not assignable to type '() => string'.
                              Type 'FieldValue' provides no match for the signature '(): string'.

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 the Date property this results problems with typing as seen on line 63

I can fix this (with some ugly unnecessary code my throwing a TypeError if the parameter isn't a Date nor a FieldValue.

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 (or Temporal).

Metadata

Metadata

Assignees

Labels

api: firestoreIssues related to the googleapis/nodejs-firestore API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions