Closed thelinuxlich closed 1 year ago
Yes, error handler need to be used inline to take advantage of typesafety.
Doesn't work inline too
if you remove the type of the parameters and let inference do it's job ?
Same thing
thank you for trying. i'll take a look into it.
Now thinking about this, if we aren't supposed to type the parameters how would it work having the routes in separate files?
Example: app.get("/transactions", transactionsGet) // how transactionsGet can have typesafety on its file?
you declare a router and share it where you want to declare your get impl. But always inline the get handler. it's the same with tRPC. everything is declared inline to have typesafety and not redeclare types manually.
I'm also getting this weird error, but it doesn't stop app
from typechecking
Full error:
[{
"resource": "/home/thelinuxlich/onepay/1p/packages/api/src/index.ts",
"owner": "typescript",
"code": "2742",
"severity": 8,
"message": "The inferred type of 'app' cannot be named without a reference to '.pnpm/@types+express-serve-static-core@4.17.30/node_modules/@types/express-serve-static-core'. This is likely not portable. A type annotation is necessary.",
"source": "ts",
"startLineNumber": 30,
"startColumn": 7,
"endLineNumber": 30,
"endColumn": 10
}]
can you show your tsconfig.json
file ?
here it is:
{
"compilerOptions": {
"target": "esnext",
"composite": true,
"incremental": true,
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"exactOptionalPropertyTypes": false,
"allowUnreachableCode": false,
"isolatedModules": true,
"noUncheckedIndexedAccess": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"preserveSymlinks": false
},
"include": ["src/**/*", "vitest.config.ts"],
"exclude": ["node_modules"]
}
Interesting, now that I looked the tsconfig, I changed the preserveSymlinks option to true and the error vanished(only remaining the errorHandler problem), but I don't know the effects of setting this flag to true, should it be recommended on the docs?
i think the default is for it to be false. So i'll try to reproducce, diagnose and fix the issue.
The only option i want to make mandatory is strict: true
.
i'll continue this tomorrow. thank you for the feedback loop.
Yeah, I just noticed that when preserveSymlinks is set to true it doesn't infer the app.use parameters
I also noticed that req.headers
doesn't get the headers from the API definition
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hello,
This should be fixed on version 10.4.5
of @zodios/express
, thank you the reports.
app in this example is a
ctx.app(api)
Full error: