-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript compilerOptions -> "strict" : true #8
Comments
Well, this is awkward. Just started getting into typeorm today, really liking it, stumbled upon this question, tried the first solution that came to my mind and it worked! In case anyone will still find it useful I'll leave it here 🤓 The solution is to type export interface Route {
path: string;
method: 'get' | 'post' | 'put' | 'delete';
action: (req: Request, res: Response) => Promise<void>;
} This way you tell typescript exactly what strings to expect in that method key, hence it does not think it is viable for an invalid key to pop up there. I omitted the last argument for the action ( Again, hope this helps someone! Happy coding! |
That is a wonderfully elegant piece of code, but it needs middleware, especially authentication middleware. Here's how to do it: Add an element to the path objects that need authentication in the
Now use this code in place of your standard
You should replace Fun! |
Hi There
In typescript-express-example/src/index.ts you have some beautifully elegant code:
`
// register all application routes
`
That registers all applications routes.
If you enable
"strict": true
in the tsconfig.json I get the error:
src/index.ts:19:4 - error TS7017: Element implicitly has an 'any' type because type 'Express' has no index signature. 19 app[route.method](route.path, (request: Request, response: Response, next: Function) => { ~~~~~~~~~~~~~~~~~
Is there a way to combine modules in this elegant way and enable strict?
Kind regards
The text was updated successfully, but these errors were encountered: