sách gpt4 ai đã đi

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

In lại 作者:行者123 更新时间:2023-12-03 22:49:48 29 4
mua khóa gpt4 Nike

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

我相信cái này ,传递给 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
}
});

}
}

1 Câu trả lời

我遇到过同样的问题。您必须将所有不同的 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/

29 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com