-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Description
Prerequisites
- I have written a descriptive issue title
Mongoose version
8.15.1
Node.js version
22.13.1
MongoDB version
8.0.4
Operating system
Linux
Operating system version (i.e. 20.04, 11.3, 10)
No response
Issue
The toJSON
method returns any
for the output type. I've attempted to specify the output type of the transform function, but due to the function signatures defined in document.d.ts
, it gets widened to any
making it pointless. Is there some method I'm missing on how to do this? Everything I've been able to find online about this (and what I've seen after poking around mongoose internals) seems to indicate there's no way to do this currently.
If it isn't possible, would it make sense to update the toJSON return type to be dynamic? It might work if the transform function required a typing to be supplied (using any
as a fallback to avoid breaking backwards compat) with generics and then toJSON would just use whatever the return type of the transform function is.