以下是本页上的教程:https://cdkworkshop.com/20-typescript/40-hit-counter/300-resources.html
我认为传递给this构造函数的Table应该是HitCounter,它是cdk.Construct的一个子构造函数。
它返回这条皮棉:
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>
}
}发布于 2020-04-28 16:41:17
我也有过同样的问题。您必须将所有不同的cdk包设置为相同的版本,请参见https://github.com/aws/aws-cdk/issues/542#issuecomment-449694450。
发布于 2020-06-24 12:55:54
指向项目路径的npx npm-check-updates -u
npm install
https://stackoverflow.com/questions/61357033
复制相似问题