Why are the parameters for collection hooks typed as being possibly undefined? #252
-
As you've probably seen, I've done a bad thing and enabled strict mode in my tsconfig.json It's saying that export const uploadHook: CollectionBeforeChangeHook = async (args) => {
if (args) {
const { req, data } = args
if (req?.files?.file) {
let uploadedFile: UploadedFile
if (Array.isArray(req.files.file)) {
uploadedFile = req.files.file[0]
} else {
uploadedFile = req.files.file
}
const adapter = getAdapter()
await adapter.upload(data.filename, uploadedFile)
}
return data
}
} Is there any situation where a hooks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
A lot of good questions in here. First up, I have no idea why Also, you don't need to return Does this answer your questions? |
Beta Was this translation helpful? Give feedback.
A lot of good questions in here. First up, I have no idea why
args
was set to being optional. We just deployed0.9.3
, which makesargs
required. That will simplify some of your logic.Also, you don't need to return
data
from collection hooks, global hooks, or field hooks. If you don't return data, Payload will fall back on the default incoming data.Does this answer your questions?