A bit of context first. The following code was previously written in javascript and is slowly being migrated to typescript. Changes cannot be made to the checkRecordsExists function that require typescript as the file needs to remain in JS to avoid it breaking everything else that we use it in.
I've got the following function (express middleware) written in a js file:
module.exports.checkRecordsExists = (Model, { idName = 'id', paramLocation = 'path', optional = false, checkSource = true, additionalChecks, idDbField = 'id' } = {}) => {
...
};
and according to VSCode the functions object parameter which should fall back to an empty object are of type string
(alias) checkRecordsExists(Model: object, { idName, paramLocation, optional, checkSource, additionalChecks, idDbField }?: string): (req: any, res: any, next: any) => Promise
This is causing the typescript compiler to complain when I try to call it like so in a ts file:
checkRecordsExists(dbService.CustomPage, { checkSource: false })
with the following error message:
Argument of type '{ checkSource: boolean; }' is not assignable to parameter of type 'string'. ts(2345)
Any ideas on how to fix this weird error without using //@ts-ignore?
import { checkRecordsExists } from '../../middleware/auth';checkRecordExistsis in Typescript but thanks for linking the documentation anyways :). Will update the postcheckRecordExiststo have the correct types?