I have some reusable
FieldHook
s where I am doing for example:
payload.findByID({
collection: req.collection.config.slug,
...
})
Because of the new type inference scheme, which I do like very much,
req.collection.config.slug
no longer fits into the
collection
parameter of payload query operations:
Type 'string' is not assignable to type '"users" | ...'.ts(2322)
The expected type comes from property 'collection' which is declared here on type 'Options<"users" | ...>'
Marking it
as any
solves the problem for now, but curious if this might be something worth looking into.
Post weekend bump (;
Ok so it sounds like
req.collection.config.slug
is typed as a generic string, but the local API will
onlyexcept the exact slugs of your collections ("users", etc). Without looking at the code, this may be able to get resolved by improving the types at the hook-level to be a union of collection slugs. For now you might be available to import the slugs from your generated types to replace your
as any
type assertion.
Exactly. The goal is that the type of
req.collection.config.slug
is already that union, rather than remaining
string
.
It would be great if that same typing could be applied to
relationTo
as well.
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.