Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. router.route('/cheeses/:id')
  2. .get(controller.showRoute)
  3.  
  4. export function showRoute(req: Request, res: Response, next: NextFunction): void {
  5. Cheese.findById(req.params.id)
  6. .then((cheese: ICheeseModel) => res.json(cheese))
  7. .catch(next)
  8. }
  9.  
  10. lib/controllers/cheeses.ts:11:30 - error TS2339: Property 'id' does not exist on type 'Params'.
  11. Property 'id' does not exist on type 'string[]'.
  12.  
  13. 11 Cheese.findById(req.params.id)
  14. ~~
  15.  
  16. {
  17. "compilerOptions": {
  18. "module": "commonjs",
  19. "moduleResolution": "node",
  20. "pretty": true,
  21. "sourceMap": true,
  22. "target": "es6",
  23. "outDir": "./dist",
  24. "baseUrl": "./lib"
  25. },
  26. "include": [
  27. "lib/**/*.ts"
  28. ],
  29. "exclude": [
  30. "node_modules"
  31. ]
  32. }
  33.  
  34. {
  35. "name": "typescript-express-api",
  36. "version": "1.0.0",
  37. "main": "index.js",
  38. "license": "MIT",
  39. "scripts": {
  40. "build": "tsc",
  41. "dev": "nodemon",
  42. "start": "node ./dist/server"
  43. },
  44. "dependencies": {
  45. "@types/express": "^4.17.0",
  46. "@types/mongoose": "^5.5.12",
  47. "@types/node": "^12.7.2",
  48. "@types/webrtc": "^0.0.25",
  49. "express": "^4.17.1",
  50. "mongoose": "^5.6.9",
  51. "ts-node": "^8.3.0",
  52. "typescript": "^3.5.3"
  53. }
  54. }
  55.  
  56. {
  57. "watch": ["lib"],
  58. "ext": "ts",
  59. "exec": "ts-node ./lib/app.ts"
  60. }
  61.  
  62. declare namespace Express {
  63. export interface Request {
  64. params: any;
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement