ARTICLE AD BOX
I'm using cors with TypeScript (strict mode) and Express. I have a function that creates a CORS middleware with custom options, but TypeScript (with @typescript-eslint) throws the following error:
Unsafe call of a type that could not be resolved
Here is my cors.ts module:
import cors, { type CorsOptions } from "cors"; import { type RequestHandler } from "express"; export const createCors = ( isProd: boolean, allowedOrigins: string[], ): RequestHandler => { const options: CorsOptions = { origin: isProd ? allowedOrigins : "*", methods: ["GET", "POST", "PUT", "PATCH", "DELETE"], allowedHeaders: ["Content-Type", "Authorization", "X-Requested-With"], exposedHeaders: ["Content-Range", "X-Content-Range"], credentials: true, maxAge: 86400, }; return cors(options); // Error: Unsafe call of a type that could not be resolved [@typescript-eslint/no-unsafe-call] };I have installed:
@types/[email protected]
@types/[email protected]
I use a strict TypeScript config:
{ "$schema": "https://www.schemastore.org/tsconfig", "display": "Strictest", "_version": "2.0.0", "compilerOptions": { /* --- Project Options --- */ "target": "esnext", "module": "preserve", "moduleResolution": "bundler", "lib": [ "ESNext" ], "types": [ "node" ], "typeRoots": [ "./node_modules/@types", "./src/infrastructure/http/express/middlewares/types" ], "baseUrl": ".", "paths": { "@config": [ "src/config/index" ], "@infrastructure/*": [ "src/infrastructure/*" ] }, "esModuleInterop": true, "skipLibCheck": true, "strict": true, "allowUnusedLabels": false, "allowUnreachableCode": false, "exactOptionalPropertyTypes": true, "noFallthroughCasesInSwitch": true, "noImplicitOverride": true, "noImplicitReturns": true, "noPropertyAccessFromIndexSignature": true, "noUncheckedIndexedAccess": true, "isolatedModules": true, "noImplicitAny": true, "useUnknownInCatchVariables": true, "noEmitOnError": true, "verbatimModuleSyntax": true, "erasableSyntaxOnly": true, "rewriteRelativeImportExtensions": true, "noUnusedLocals": true, "noUnusedParameters": true, "removeComments": true, "sourceMap": true, "inlineSources": true }, "files": [], "references": [ { "path": "./tsconfig.app.json" }, { "path": "./tsconfig.spec.json" } ] }Any ideas?
