gpt4 book ai didi

typescript - TS2345 : type 'Construct' is not a class derived from 'Construct'

转载 作者:行者123 更新时间:2023-12-03 22:49:48 28 4
gpt4 key购买 nike

按照此页面上的教程:https://cdkworkshop.com/20-typescript/40-hit-counter/300-resources.html

我相信this ,传递给 Table构造函数,应该是 HitCounter , cdk.Construct的子构造器

它返回这个 lint:

this: this
Argument of type 'this' is not assignable to parameter of type 'Construct'.
Type 'HitCounter' is not assignable to type 'Construct'.
Property 'onValidate' is protected but type 'Construct' is not a class derived from 'Construct'.ts(2345)

在这一步我也收到内部服务器错误。有谁知道是什么问题?
import * as cdk from "@aws-cdk/core";
import * as lambda from "@aws-cdk/aws-lambda";
import * as dynamodb from "@aws-cdk/aws-dynamodb";

export interface HitCounterProps { downstream : lambda.IFunction; }

export class HitCounter extends cdk.Construct {
public readonly handler: lambda.Function;

constructor(scope: cdk.Construct, id: string, props: HitCounterProps) {
super(scope, id);

const table = new dynamodb.Table(this, "Hits", { // lints `this`
partitionKey : {
name : "path",
type : dynamodb.AttributeType.STRING
}
});
<more code removed>
}
}

最佳答案

我遇到过同样的问题。您必须将所有不同的 cdk 包设置为相同的版本,请参阅 https://github.com/aws/aws-cdk/issues/542#issuecomment-449694450 .

关于typescript - TS2345 : type 'Construct' is not a class derived from 'Construct' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61357033/

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