gpt4 book ai didi

node.js - 类型 'this' 的参数无法分配给参数 'Construct'

转载 作者:太空宇宙 更新时间:2023-11-03 22:04:03 25 4
gpt4 key购买 nike

我试图将 lambda 函数调用到“示例应用程序”堆栈中,但它给了我一个错误,因为我试图向它传递“this”参数。

这是我的 lambda 函数

export async function handler(event) {
console.log("request:", JSON.stringify(event, undefined, 2));
return {
statusCode: 200,
headers: { "Content-Type": "text/plain" },
body: `Hello, CDK! You've hit ${event.path}\n`
};
};

这是调用该函数的“应用程序”

//import sns = require('@aws-cdk/aws-sns');
//import subs = require('@aws-cdk/aws-sns-subscriptions');
//import sqs = require('@aws-cdk/aws-sqs');
import cdk = require('@aws-cdk/core');
import lambda = require('@aws-cdk/aws-lambda');

//Exports class from other file much like a function

export class CdkWorkshopStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);

// Describes an AWSLambda Resource
const hello = new lambda.Function (this, 'HelloHandler', {
runtime: lambda.Runtime.NODEJS_8_10, //execution environment
code: lambda.Code.asset('lambda'), // code loaded from the "lambda" directory
handler: 'hello.handler' // file is "hello", function is "handler"
});
}
}

我收到的错误是:


lib/cdk-workshop-stack.ts:31:39 - error TS2345: Argument of type 'this' is not assignable to parameter of type 'Construct'.
Type 'CdkWorkshopStack' is not assignable to type 'Construct'.
Types of property 'node' are incompatible.
Type 'import("/Users/aroe/cdk-workshop/node_modules/@aws-cdk/core/lib/construct").ConstructNode' is not assignable to type 'import("/Users/aroe/cdk-workshop/node_modules/@aws-cdk/aws-lambda/node_modules/@aws-cdk/core/lib/construct").ConstructNode'.
Types have separate declarations of a private property 'host'.

31 const hello = new lambda.Function(this, 'HelloHandler', {
~~~~

[1:24:08 PM] Found 1 error. Watching for file changes.

最后我使用的是 Node 版本 v13.3.0

最佳答案

这个构造定义对我来说看起来很正确。如果各个 cdk 模块的版本不同,则可能会发生该错误;请参阅Argument of type 'this' is not assignable to parameter of type 'Construct'举一个例子。尝试运行npm update;看看是否可以解决问题。

关于node.js - 类型 'this' 的参数无法分配给参数 'Construct',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59381686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com