TS2345:类型'Construct'不是从'Construct'派生的类

问题描述 投票:1回答:1

按照此页面上的教程: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>
   }
}
typescript
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.