I have some reusable
FieldHooks 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.slugno longer fits into the
collectionparameter 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 anysolves 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.slugis 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 anytype assertion.
Exactly. The goal is that the type of
req.collection.config.slugis already that union, rather than remaining
string.
It would be great if that same typing could be applied to
relationToas well.
Star
Discord
online
Get dedicated engineering support directly from the Payload team.