类型“ void”的参数不能分配给“ PathParams”类型的参数

时间:2019-11-13 12:11:11

标签: node.js typescript express

创建路线TASK [debug] ******************************************************************* ok: [localhost] => { "failed": false, "lambda_config": { "changed": true, "msg": "All items completed", "results": [ { "_ansible_ignore_errors": null, "_ansible_item_result": true, "_ansible_no_log": false, "_ansible_parsed": true, "changed": true, "code": { "location": "https://awslambda-eu-west-2-tasks.s3.eu-west-2.amazonaws.com/snapshots/****/cloudwatch-to-slack-cf94f4d9-fc73-495b-aff5-b6c619d38b28?versionId=kzf3OeHyAo1KAYF.WidtJch0730rckRa&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEAYaCWV1LXdlc3QtMiJHMEUCIQCjBXJcZKqxWX%2FMuj0zrAWO2UMMVyY22sCB%2Fo4YM02yqgIgBXVv0h2efZNqtjOJuyJlUAU0ou6StJLTXiBQzn%2B5BY4q0gIILhABGgw0NzIwMzg4NjQxODgiDDWKUw4k946LccANVCqvAgv5WC7AbvV9IhdAd3kXXGIxTqnRYJsneoNXYgf3BC3tRAYxrq2D0u0iL7HAqGqL97L6IRneu4H5pDqHalSfgBvriSrI8hDpDLsNJ08d9pMFigOWM9HWpi0rCwkRRG7FSjNgT4oqqZwUEcQl7H36a53qAdFGUp60S6Y4nZxuOkg3jgiyx6fkyXy8MAWxk8A6AogKQc0uubhcIbJNMGLrF3uyoROONdXNVtbJzkIQOZdoXxDW%2BMOr%2BBuyOz8%2F6RZqyiS3FkKCRuhl5GFueSDIW1ZUjzw68aRi1%2BFoCkIjxvf5cvfxwkOYW0UculsbAzv82F1CA3foeKUpR%2FWzUl5HRKzzB7MuZNntwac7rPOSbDNgAvbAdRibbUUbETDnBm7BmMalx9V%2BMXeK%2BHNHuk2eQDDsnbDuBTrNAl6I1SKoiX0iU5lvWmm8yXpE8NEA98g%2F1xzbmGlMPAFDg3sX19zts5xK%2BcYuZ9NG1kfReW7lo7kDVCTvGIhZmF9%2B%2FK2mmo%2FIoTYY6v7WygsrgyG2QGaE%2B5BdljJ1Kpb05We1v877JJNxrwX%2BhyUH2iD8wJS4k2bMum%2FytT02YnX014kSW21V6UVqMYftmcZ%2BYAE%2BQWdxqYgJtry9ZJFEdwwYAkJ2wgvqoLtBK3aaVQRDYw0TXtOnATi5EVn%2FQobtNO%2BXVmqflcGdJrtlVapFqKqX17eJw6KvnRo9%2BeMQ5OAKMt6xVA1p%2F3uxxIhQuyB9b8maRMg3TWfiUs%2FpYhjHQI%2FDaz00dAllvQBvjR%2FFjAeP76%2BVQzpiBW1tLQTBqzJZ1aQqfOB7vV6KkqSok%2BndT1hFwRbFgf76AboKGfwWuVHh7g0aWtnzQ%2FFF%2Fmizcg%3D%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20191113T150904Z&X-Amz-SignedHeaders=host&X-Amz-Expires=600&X-Amz-Credential=ASIAW3Z5VOU6FMHUHSL2%2F20191113%2Feu-west-2%2Fs3%2Faws4_request&X-Amz-Signature=eb46bba09f8496841d67f2b24a042b0a3467fae7adcf1149bb8ca1e269f1604e", "repository_type": "S3" }, "configuration": { "code_sha256": "LmvHp5ZwvJXHK4pvVFOQqjtW13izWo2Kv4sJ6l1j7XY=", "code_size": 12098675, "description": "", "function_arn": "arn:aws:lambda:eu-west-2:****:function:cloudwatch-to-slack:20", "function_name": "cloudwatch-to-slack", "handler": "lambda.lambda_handler", "last_modified": "2019-11-13T15:09:04.488+0000", "memory_size": 128, "revision_id": "cd9af309-a209-4630-897a-9ee5e7c164cb", "role": "arn:aws:iam::****:role/devops-lambdas", "runtime": "python3.6", "timeout": 3, "tracing_config": { "mode": "PassThrough" }, "version": "20" }, "failed": false, "invocation": { "module_args": { "aws_access_key": null, "aws_secret_key": null, "dead_letter_arn": null, "description": "", "ec2_url": null, "environment_variables": null, "handler": "lambda.lambda_handler", "memory_size": 128, "name": "cloudwatch-to-slack", "profile": null, "region": "eu-west-2", "role": "arn:aws:iam::****:role/devops-lambdas", "runtime": "python3.6", "s3_bucket": "my-devops-lambdas-eu-west-2", "s3_key": "cloudwatch-to-slack.zip", "s3_object_version": null, "security_token": null, "state": "present", "tags": null, "timeout": 3, "validate_certs": true, "vpc_security_group_ids": null, "vpc_subnet_ids": null, "zip_file": null } }, "item": [ "cloudwatch-to-slack", "eu-west-2", "arn:aws:sns:eu-west-2:****:slack_devops" ], "response_metadata": { "http_headers": { "connection": "keep-alive", "content-length": "2451", "content-type": "application/json", "date": "Wed, 13 Nov 2019 15:09:04 GMT", "x-amzn-requestid": "deb5eab6-39d8-451c-851a-096da70056ee" }, "http_status_code": 200, "request_id": "deb5eab6-39d8-451c-851a-096da70056ee", "retry_attempts": 0 } }, { "_ansible_ignore_errors": null, "_ansible_item_result": true, "_ansible_no_log": false, "_ansible_parsed": true, "changed": true, "code": { "location": "https://awslambda-eu-west-1-tasks.s3.eu-west-1.amazonaws.com/snapshots/****/cloudwatch-to-slack-dad6d47a-b4d6-4d03-8300-e9a47e652415?versionId=510url5wG1BMpTNk047YFeKYDpPwH9HH&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEAYaCWV1LXdlc3QtMSJGMEQCIBXrZqSZ4rvZKX27JqGrh2I1lUXqcYbFEu65TsYYaD7yAiBACK9qTPJFttLMbhNglvrKI%2F80hGO2hRn2wlRHIcY2hSrRAgguEAEaDDk1NDM2OTA4MjUxMSIMEQgZtz75PVoFjg%2FSKq4CYnr%2BXPNGag8Y5s3mncAQJbftOPYRffNPV1tsJcN%2BEYANTgKaiNBv%2FkOLpKLNaTuTtPZVa%2F6PO20zsD6GBK%2BeQL0craOJhNmawU50vpRlGIWyQKHhPyGbidr3%2FjE6eN%2B9TfHmrp2HyxfOy8L8wMfa%2BuuRfSsVlE3qdu57zhXCOClb2HFcbDrOLCS%2BFyDuFAFxDmeZ8wLlOv%2BiSIJvwX0LcXNHXmRhpKbqQ%2F8tsOLkwnfW80ri5PVvO9f9%2FOq5spEC8PWNbaSp5TEsnzPodM14PD1E4TIDn1UogDueIUvZ2nJRHCGw4P7glzI78e1NcMPT5eJAr2zT50V3nkT%2FlKgX5M7tnFhnW9IXdHxTIOIwjtVun4jUCSFh5897wPTb39tGLl163sCuM8FjxMKC5Lowy52w7gU6zwIOVYWYv%2B02dlMT5TV0mOCHxXnGx4DEORRcYJyVAHNVLK0%2BLaFcNWcS6YLKWNnSwBVc0uL2agamVB%2FU1bOBNBePTtT71icqxaMBfgOeztW%2BdH9Z%2BtH9e49QBCR4RqtuWd%2BdqW2oSwU78qiHYDbD0C6I9ncp546Q96BkEy%2FGTdSxLHr6dK%2BzGC5B39z6Vm8U4vEr22%2B8q44PuRx6dvIAE36VoiE9yEVJ4lAePb924VHEgnSxFEWUxQwNeoRcydU2%2BD1X34%2FForAo8upzZDOJl47eSv5SsQltGi0FsTkvhCld9aYT3EKWywXp8AJUalWSONtFXToh5xCc%2F3chuho5MkssdShdXi3wpX9epgRP0rYFSOh0VoeTZ6PauQ2B8dzK58adkwvTXuefYzNk6Yei%2Bei%2B8Wn0%2FIbU8k5L0YAiT%2FMrObPjtbcVmFRY%2FWYDlc8G7g%3D%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20191113T150906Z&X-Amz-SignedHeaders=host&X-Amz-Expires=600&X-Amz-Credential=ASIA54NGUQSH3ABZBRID%2F20191113%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Signature=8cb09d879f729f19d01c11fc2deb1d49a6e409f2284878d879e6f197ad73f67d", "repository_type": "S3" }, "configuration": { "code_sha256": "cW3LqsTkdXwBacHpRvgfruZ7svIhy7gvB80keZqVpjw=", "code_size": 12100273, "description": "", "function_arn": "arn:aws:lambda:eu-west-1:****:function:cloudwatch-to-slack:21", "function_name": "cloudwatch-to-slack", "handler": "lambda.lambda_handler", "last_modified": "2019-11-13T15:09:05.780+0000", "memory_size": 128, "revision_id": "e48a6926-fd7c-44f8-9e1f-3f24e0fc82fb", "role": "arn:aws:iam::****:role/devops-lambdas", "runtime": "python3.6", "timeout": 3, "tracing_config": { "mode": "PassThrough" }, "version": "21" }, "failed": false, "invocation": { "module_args": { "aws_access_key": null, "aws_secret_key": null, "dead_letter_arn": null, "description": "", "ec2_url": null, "environment_variables": null, "handler": "lambda.lambda_handler", "memory_size": 128, "name": "cloudwatch-to-slack", "profile": null, "region": "eu-west-1", "role": "arn:aws:iam::****:role/devops-lambdas", "runtime": "python3.6", "s3_bucket": "my-devops-lambdas-eu-west-1", "s3_key": "cloudwatch-to-slack.zip", "s3_object_version": null, "security_token": null, "state": "present", "tags": null, "timeout": 3, "validate_certs": true, "vpc_security_group_ids": null, "vpc_subnet_ids": null, "zip_file": null } }, "item": [ "cloudwatch-to-slack", "eu-west-1", "arn:aws:sns:eu-west-1:****:slack_devops" ], "response_metadata": { "http_headers": { "connection": "keep-alive", "content-length": "2453", "content-type": "application/json", "date": "Wed, 13 Nov 2019 15:09:06 GMT", "x-amzn-requestid": "78704b46-7dce-49c1-961e-cb8882088566" }, "http_status_code": 200, "request_id": "78704b46-7dce-49c1-961e-cb8882088566", "retry_attempts": 0 } } ] } } 并添加到我的handler中。

route

路线

import {Application, NextFunction} from 'express';
import {container} from 'tsyringe';
const routeConstantsArray  = { };

const constants: any  = []
constants.push(routeConstantsArray)
let next : NextFunction;
export const loadConstantsMiddleware = (app:Application) => {
    app.locals = constants
    next();
};

错误
 (参数)应用:import express from 'express'; import {Application} from 'express'; import cors from 'cors'; // Import Internal Modules import {loadConstantsMiddleware} from '../core/middleware/constants_middleware'; const startupRouterConfig = (app: Application): Application => { app.use(cors()); app.use(express.json()); app.use(loadConstantsMiddleware(app)); return app; };     没有重载匹配此调用。       最后一次重载给出了以下错误:

express.Application

1 个答案:

答案 0 :(得分:0)

要将loadConstantsMiddleware用作中间件,必须返回请求处理程序,例如:

export const loadConstantsMiddleware = (app:Application) => {
    app.locals = constants;
    return (req, res, next) => {
      next();
    }
};

但是在这种情况下,将其用作中间件可能没有任何意义,因为常量的作用域是整个应用程序(仅是请求的作用域)。

要将其直接添加到应用程序中,而无需中间件,则可以执行以下操作:

// main
app.use(cors());
app.use(express.json());
loadConstantsMiddleware(app);

// load-constants-middleware
export const loadConstantsMiddleware = (app:Application) => {
  app.locals = constants
};